This can be done very easily. We will provide you with the solution based on a dialog resource. Please add a custom control to your dialog. The location of the control is not important. Open its property dialog and fill in all the parameters like in any other custom control in the IDD_PAGE_TOOLBARS dialog resource of the ProfUIS_Controls sample application. Then add:
-
CExtToolControlBar m_wndToolbar;
the property to your dialog class. DDX_Control(pDX, IDC_CUSTOM1, m_wndToolBar);
the line to the DoDataExchange()
method of your dialog class.
You can take a look at the
CPageToolbars
class of the
ProfUIS_Controls sample application to see how it can be done.
To load your toolbar, add the following lines to the
CYourDialog::OnInitDialog()
method:
ASSERT( m_wndToolBar.GetSafeHwnd() != NULL );
if( !m_wndToolBar.LoadToolBar( IDR_YOUR_TOOLBAR_RESOURCE ) ){
ASSERT( FALSE );
return FALSE;
}
To stick your toolbar to the dialog window side, do the following:
1) put this line near at the end
CYourDialog::OnInitDialog():
CWnd::RepositionBars(0,0xFFFF,0);
2) handle the
WM_SIZE
windows message:
void CYourDialog::OnSize(UINT nType, int cx, int cy)
{
CPageBase::OnSize(nType, cx, cy);
if( nType != SIZE_MINIMIZED )
CWnd::RepositionBars(0,0xFFFF,0);
}
The toolbar is now completely initialized and you can handle the
WM_COMMAND
messages sent from its buttons. Just work with your toolbar commands absolutely like in a
CFrameWnd
-based application.
Here is the sample of a command handler (the declaration, dialog message map entry, and implementation):
afx_msg void OnLook2005();
ON_COMMAND(IDC_THEME_STUDIO_2005, OnLook2005)
void CYourDialog::OnLook2005()
{
}
Here is the sample of a command updating handler (the declaration, dialog message map entry, and implementation):
afx_msg void OnUpdateLook2005(CCmdUI* pCmdUI);
ON_UPDATE_COMMAND_UI(IDC_THEME_STUDIO_2005, OnUpdateLook2005)
void CYourDialog::OnUpdateLook2005(CCmdUI* pCmdUI)
{
pCmdUI->Enable();
}
That’s all.