由于需要,最近需要对CDialogBar进行编程,所以查了N多资料,并陆续整理成学习笔记

 

第一篇       CDialogBarVC6.0中的基本使用

 

VC中,如果只是简单的使用CButton之类的东西,是不需要使用CDialogBar类的,您只要简单使用CToolBar之类的就行了,但如果您要使用 CCombobox, CTreeview, 或者是ActiveX control之类的就需要该类了。

http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B185672这篇文章中,述了如何使用CDialogBar的基本用法

 

在使用向导生成自己的类基于CDialog的类之后要进行以下6

1、更改基类为CDialogBar,同时也要改BEGIN_MESSAGE_MAP 中的基类。

2、更改构造函数、DoDataExchange(),即

CMyDlgBar (CWnd* pParent = NULL);   // standard constructor

 

CMyDlgBar:: CMyDlgBar (CWnd* pParent /*=NULL*/)

    CDialog(CMyDlgBar::IDD, pParent)

{

...

 

void CMyDlgBar::DoDataExchange(CDataExchange* pDX)

{

    Dialog::DoDataExchange(pDX);   

CDialogBar::DoDataExchange(pDX); // <-加上这一行.

    ..

 3、从类的头文件中删除

virtual BOOL OnInitDialog();

并添加

afx_msg LONG OnInitDialog ( UINT, LONG );

如下:

class CMyDlgBar : public CDialogBar

{

     ...

     // Implementation

     protected:

 

     // Generated message map functions

     //{{AFX_MSG(CMyDlgBar)

virtual BOOL OnInitDialog();

     //}}AFX_MSG

 

     afx_msg LONG OnInitDialog ( UINT, LONG );   // <-加上这一行.

     DECLARE_MESSAGE_MAP()

};

4、在CPP文件中加入WM_INITDIALOG消息映射

BEGIN_MESSAGE_MAP(CMyDlgBar, CDialogBar)

 

         //{{AFX_MSG_MAP(CMyDlgBar)

         ...

         //}}AFX_MSG_MAP

         ON_MESSAGE(WM_INITDIALOG, OnInitDialog )    // <-- 加上这一行.

      END_MESSAGE_MAP()

5、添加OnInitDialog函数并更改,如下:

LONG CMyDlgBar::OnInitDialog ( UINT wParam, LONG lParam)

{

CDialog::OnInitDialog();

 

    // <-- 加上以下几行. -->

    BOOL bRet = HandleInitDialog(wParam, lParam);

    if (!UpdateData(FALSE))

    {

        TRACE0("Warning: UpdateData failed during dialog init.\n");

    }

    ...

 

     return bRet;

6、在资源管理器中更改对话框的类型如下:

Style: Child

Boarder: None

Visible: Unchecked

 

经过以上六步你就可以按正常的方法使用CdialogBar了。什么叫正常的方法,CDialogBar派生自CContorBar

而要让CdialogBar中控件变为“可见”,则还需做一件事,就是为控件提供Command Handler函数,而该函数必须是CdialogBar的父窗口以上的对象。