Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to add CMFCToolBar object on CDialog derived class.
Toolbar got added, but button on the toolbar is not enabled, because application is not able to locate its handler. Though I have provided them in dialog class.

Please refer below sample code.

MyDlg.h File
C#
class CMyDlg : public CDialog
{
...
CMFCToolBar m_ToolBar;
...
}

MyDlg.cpp File

C#
void CMyDlg::CreateToolbar()
{
	if( m_ToolBar.CreateEx(this, TBSTYLE_TRANSPARENT | TBSTYLE_FLAT, 
		AFX_DEFAULT_TOOLBAR_STYLE, CRect(1, 1, 1, 1), IDC_TOOLBAR) )
	{
		m_ToolBar.SetPaneStyle( m_ToolBar.GetPaneStyle() 
			& ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_ANY) );

		m_ToolBar.SetBorders ();

		m_ToolBar.LoadBitmap(IDB_MAIN_CONTAINER_TOOLBAR);

		m_ToolBar.InsertButton( CMFCToolBarButton(ID_MAIN_CONTAINER_TB_HOME, 0, _T("Home"), TRUE ) );


		CSize   sizeToolBar = m_ToolBar.CalcFixedLayout( FALSE, TRUE );
		m_ToolBar.SetWindowPos(NULL, 0, 10, sizeToolBar.cx, sizeToolBar.cy,
			SWP_NOACTIVATE | SWP_NOZORDER );

	}
}

BOOL CMyDlg::OnInitDialog()
{
    CreateToolbar();
    return TRUE;
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
    ON_WM_SIZE()
    ON_COMMAND(ID_MAIN_CONTAINER_TB_HOME, OnHome)
    ON_UPDATE_COMMAND_UI(ID_MAIN_CONTAINER_TB_HOME, OnUpdateCmdUIToolbar)
END_MESSAGE_MAP()

void DFMDlgMainContainerNew::OnHome()
{}
void DFMDlgMainContainerNew::OnUpdateCmdUIToolbar(CCmdUI* pCmdUI)
{
    pCmdUI->Enable();
}


Your help would be highly appreciated.

Thanks,
Paresh.
Posted
Updated 5-Nov-12 0:30am
v3

1 solution

I think, the framework is seraching for a CFrameWnd-derived parent for the commands check,
so you have to place a CYourFrameWnd : public CFrameWnd(Ex) window on to the dialog
and then the bar inside. Of course the frame can delegate any infos at the dialog :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900