CDialogBar在VC6.0中的基本使用

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

/jqandjq/article/details/3762205

CDialogBar在VC6.0中的基本使用

2009-01-12 19:43 1136人阅读评论(1) 收藏举报在VC中,如果只是简单的使用CButton之类的东西,是不需要使用CDialogBar类的,您只要简单使用CToolBar之类的就行了,但如果您要使用CCombobox, CTreeview, 或者是ActiveX control之类的就需要该类了。

在/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的父窗口以上的对象。

重新此时, 一切已被连接进行正常转换到CDialogBar 类从CDialog 类。现在, 创建并使用它。

7. 将派生CDialogBar 的实例添加到CframeWnd - 派生类(通常称为CMainFrame)。例如:

class CMainFrame : public CFrameWnd

{

...

CMyDlgBar m_myDlgBar;

...

};

8. 为CFrameWnd::OnCreate() 方法中m_myDlgBar 变量调用创建方法类似于以下内容:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

...

if (!m_myDlgBar.Create(this, IDD_DLGBAR1, CBRS_LEFT,

IDD_DLGBAR1))

{

TRACE0("Failed to create dialog bar/n");

return -1; // fail to create

}

...

}

9. 最后, 如果要支持动态停靠和调整是CDialogBar, 将下行添加到末尾CMainFrame::OnCreate():

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

相关文档
最新文档