// Let MFC Create the control
// Call the base class Create()
if(!CDialogBar::Create(pParentWnd,
lpszTemplateName, /*(nIDTemplate) for other Create()*/
nStyle, nID))
{
return FALSE;
}
// Since there is no WM_INITDIALOG message we have to call
// our own InitDialog function ourselves after m_hWnd is valid
if(!OnInitDialogBar())
return FALSE;
return TRUE;
下面是使用OnInitDialogBar的一个例子:
BOOL CMainDialogBar::OnInitDialogBar()
{
// Support for DDX mechanism
// If you do not want DDX then
// do not call base class
// All out DDX controls are intialized
// the virtual call to DoDataExchange.
CInitDialogBar::OnInitDialogBar();
// Initialize any controls NOT supported by DDX
// CBitmapButton is one
m_OKButton.AutoLoad(IDOK, this);
BEGIN_MESSAGE_MAP(CInitDialogBar, CDialogBar)
//{{AFX_MSG_MAP(CInitDialogBar)
// NOTE - the ClassWizard will add and remove mapping macros
here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CInitDialogBar::CInitDialogBar()
{
// In derived classes set intial
// state of control(s) here
}
CInitDialogBar::~CInitDialogBar()
{
}
BOOL CInitDialogBar::Create(CWnd * pParentWnd, LPCTSTR lpszTemplateName,
UINT nStyle, UINT nID)
{
// Let MFC Create the control
if(!CDialogBar::Create(pParentWnd, lpszTemplateName, nStyle, nID))
return FALSE;
// Since there is no WM_INITDIALOG message we have to call
// our own InitDialog function ourselves after m_hWnd is valid
if(!OnInitDialogBar())
return FALSE;
// Since there is no WM_INITDIALOG message we have to call
// our own InitDialog function ourselves after m_hWnd is valid
if(!OnInitDialogBar())
return FALSE;
return TRUE;
}
BOOL CInitDialogBar::OnInitDialogBar()
{
// Support for the MFC DDX model
// If you do not want this do not call the base class
// from derived classes
UpdateData(FALSE);
return TRUE;
}
void CInitDialogBar:oDataExchange(CDataExchange* pDX)
{
//Derived Classes Overide this function
ASSERT(pDX);
CDialogBar:oDataExchange(pDX);
// In derived class call the DDX_??? functions to set/retrieve values
// of your controls. See example derived class for how to do this.
}
头文件:
//////////////////////////////////////////////////////////////////////
//
// MainDialogBar.h: interface for the CMainDialogBar class.
//
//////////////////////////////////////////////////////////////////////
BOOL CMainDialogBar::OnInitDialogBar()
{
// Support for DDX mechanism
// If you do not want DDX then
// do not call base class
CInitDialogBar::OnInitDialogBar();
// Update any controls NOT supported by DDX
// CBitmapButton is one
m_OKButtton.AutoLoad(IDOK, this);
// DDX_??? functions to associate control with
// data or control object
// Call UpdateData(TRUE) to get data at any time
// Call UpdateData(FALSE) to set data at any time