在VC6中使用CDialogBar类

在VC6中可以在资源中新建DialogBar的对话框资源,但在类向导中创建新类时却不见CDialogBar的踪影。好在MSDN上有手动添加的方法可以参考。

1.在新建类(CMyDiagBar)时,将基类选为CDialog

2.在MyDiagBar.cpp中修改消息映射定义

BEGIN_MESSAGE_MAP(CMyDiagBar, CDialog)       //原始

BEGIN_MESSAGE_MAP(CMyDiagBar, CDialogBar)   //修改后

3.在MyDiagBar.h中修改

class CMyDiagBar : public CDialog         //原始

class CMyDiagBar : public CDialogBar    //修改后

4.修改构造函数

原始:

CMyDiagBar(CWnd* pParent = NULL);        //MyDiagBar.h中  

CMyDiagBar::CMyDiagBar(CWnd* pParent /*=NULL*/)
       :CDialog(CMyDiagBar::IDD, pParent)        //MyDiagBar.cpp中

修改后:

CMyDiagBar();      //MyDiagBar.h中  

CMyDiagBar::CMyDiagBar()     //MyDiagBar.cpp中

5.在MyDiagBar.cpp中修改成员函数DoDataExchange(...)函数体

CDialog::DoDataExchange(pDX);         //原始

CDialogBar::DoDataExchange(pDX);    //修改后

至此,新类已经可以编译无误了。特例是:如果你要新类响应WM_INITDIALOG消息的话,需要继续如下的修改

1.为新类添加WM_INITDIALOG消息的处理函数

2.在MyDiagBar.h中修改消息函数声明

原始:

// Generated message map functions
//{{AFX_MSG(CMyDiagBar)
virtual BOOL OnInitDialog();         //删除此行
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

修改后:

// Generated message map functions
//{{AFX_MSG(CMyDiagBar)
//}}AFX_MSG
afx_msg LONG OnInitDialog ( UINT, LONG );     //添加此行
DECLARE_MESSAGE_MAP()

3.在MyDiagBar.cpp中修改消息映射定义

原始:

BEGIN_MESSAGE_MAP(CMyDiagBar, CDialogBar)
//{{AFX_MSG_MAP(CMyDiagBar)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

修改后:

BEGIN_MESSAGE_MAP(CMyDiagBar, CDialogBar)
//{{AFX_MSG_MAP(CMyDiagBar)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_INITDIALOG, OnInitDialog )   //添加此行
END_MESSAGE_MAP()

4.在MyDiagBar.cpp中修改OnInitDialog(...)函数

原始:

BOOL CMyDiagBar::OnInitDialog()
{
CDialogBar::OnInitDialog();
return TRUE;  
}

修改后:

LONG CMyDiagBar::OnInitDialog ( UINT wParam, LONG lParam)
{
BOOL bRet = HandleInitDialog(wParam, lParam);
if (!UpdateData(FALSE))
{
TRACE0("Warning: UpdateData failed during dialog init./n");
}
return bRet;
}

到此为止,新类已经完全修改为CDialogBar的继承类了。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CDialogBar是MFC框架的一个,用于实现在主窗口添加一个似工具栏的窗口。如果需要自定义CDialogBar的外观或者添加自己的控件,可以通过派生CDialogBar来实现。 具体实现步骤如下: 1. 创建一个CDialogBar的派生,例如MyDialogBar。 2. 在MyDialogBar.h文件添加需要添加的控件,例如: ``` class MyDialogBar : public CDialogBar { public: MyDialogBar(); virtual ~MyDialogBar(); // Dialog Data #ifdef AFX_DESIGN_TIME enum { IDD = IDD_MYDIALOGBAR }; #endif protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support virtual BOOL OnInitDialog(); DECLARE_MESSAGE_MAP() private: CButton m_btnTest; }; ``` 3. 在MyDialogBar.cpp文件实现OnInitDialog()函数,用于初始化添加的控件。例如: ``` BOOL MyDialogBar::OnInitDialog() { CDialogBar::OnInitDialog(); // TODO: Add extra initialization here m_btnTest.Create(_T("Test"), WS_CHILD | WS_VISIBLE, CRect(10, 10, 100, 30), this, IDC_BTN_TEST); return TRUE; // return TRUE unless you set the focus to a control } ``` 4. 在主窗口添加MyDialogBar控件,例如: ``` BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { // TODO: Add your specialized code here and/or call the base class m_wndSplitter.CreateStatic(this, 1, 2); m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CMyView), CSize(0, 0), pContext); m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CListView), CSize(0, 0), pContext); m_wndMyDialogBar.Create(this, IDD_MYDIALOGBAR, CBRS_LEFT, IDD_MYDIALOGBAR); m_wndMyDialogBar.EnableDocking(CBRS_ALIGN_LEFT); DockControlBar(&m_wndMyDialogBar); return TRUE; } ``` 通过以上步骤,就可以自定义CDialogBar的外观和添加自己的控件了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值