在CDialog上添加CMFCToolBar对象 [英] Adding CMFCToolBar object on CDialog

查看:107
本文介绍了在CDialog上添加CMFCToolBar对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试在CDialog派生类上添加CMFCToolBar对象.
添加了工具栏,但是未启用工具栏上的按钮,因为应用程序无法找到其处理程序.尽管我在对话框类中提供了它们.

请参考下面的示例代码.

MyDlg.h文件

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

class CMyDlg : public CDialog
{
...
CMFCToolBar m_ToolBar;
...
}


MyDlg.cpp文件


MyDlg.cpp File

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();
}



非常感谢您的帮助.

谢谢,
Paresh.



Your help would be highly appreciated.

Thanks,
Paresh.

推荐答案

我认为,该框架正在为CFrameWnd派生的父级搜索命令检查,
因此您必须在对话框上放置CYourFrameWnd : public CFrameWnd(Ex)窗口
然后里面的酒吧.当然,框架可以在对话框中委派任何信息:)
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 :)


这篇关于在CDialog上添加CMFCToolBar对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆