Article ID: 185672
Article Last Modified on 11/21/2006
CMyDlgBar (CWnd* pParent = NULL); // standard constructor
CMyDlgBar:: CMyDlgBar (CWnd* pParent /*=NULL*/)
: CDialog(CMyDlgBar::IDD, pParent)
{
...
void CMyDlgBar::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
...
to the following:
CMyDlgBar (); // standard constructor
CMyDlgBar:: CMyDlgBar ()
{
...
void CMyDlgBar::DoDataExchange(CDataExchange* pDX)
{
CDialogBar::DoDataExchange(pDX);
...
The key to the transformation is the conversion of the virtual
OnInitDialog() member function to the WM_INITDIALOG message mapped
method by changing the OnInitDialog method and by adding the
ON_MESSAGE() handler. You may not have an override of OnInitDialog(). If
not, add one before proceeding.
class CMyDlgBar : public CDialogBar
{
...
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CMyDlgBar)
virtual BOOL OnInitDialog(); // <-Remove this line.
//}}AFX_MSG
afx_msg LONG OnInitDialog ( UINT, LONG ); // <-Add this line.
DECLARE_MESSAGE_MAP()
};
Now, in the class implementation section, make the corresponding
changes.
BEGIN_MESSAGE_MAP(CMyDlgBar, CDialogBar)
//{{AFX_MSG_MAP(CMyDlgBar)
...
//}}AFX_MSG_MAP
ON_MESSAGE(WM_INITDIALOG, OnInitDialog ) // <-- Add this line.
END_MESSAGE_MAP()
Now, convert the virtual OnInitDialog() to the message-mapped
OnInitDialog().
Change the following:
BOOL CMyDlgBar::OnInitDialog()
{
CDialog::OnInitDialog(); // <-- Replace this line:
...
to the following:
LONG CMyDlgBar::OnInitDialog ( UINT wParam, LONG lParam)
{
// <-- with these lines. -->
BOOL bRet = HandleInitDialog(wParam, lParam);
if (!UpdateData(FALSE))
{
TRACE0("Warning: UpdateData failed during dialog init.\n");
}
...
return bRet;
The CDialogBar class doesn't have a virtual OnInitDialog(), and
therefore calling one does not work. UpdateData is called to subclass
or initialize any child controls.
Style: Child
Boarder: None
Visible: Unchecked
class CMainFrame : public CFrameWnd
{
...
CMyDlgBar 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
}
...
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
m_myDlgBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_myDlgBar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_myDlgBar);
return 0;
}99161 How to derive from classes not listed in ClassWizard
Keywords: kbhowto kbmfcctrlbar kbuidesign kbwizard KB185672