在对话框程序中插入DialogBar

在基于MainFrm程序中加入DialogBar很方便,大家都知道,DialogBar有着工具条无法比拟的优越性,它可以任意放置控件,轻松实现如WPS OFFICE的导航功能。但是在基于Dialog的程序怎么实现这种导航功能呢?本文拟针对这个问题提出解决的办法,将困扰本人很久的问题的解决方法和大家一同分享。

大家都知道,CDialogBar不能在Dialog程序中产生的原因是Dialog中没有MainFrm,所以我就从CMiniFrameWnd产生了自己的一个类CMyMiniFrm。

 
 
BOOL CMyMiniFrm::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	// pass those up in the dialog to leave the OnUpdateUI mechanism to flow
	BOOL br = GetParent()->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
	// leave the default proc to handles the tooltip updating mechanism
	CMiniFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
	return br;	// return what the parent returns
}

然后,我们可以从Cstatic产生自己的生成Cdialog类了,其中创建CDialogBar的代码如下

 
 
void CStTbar::PreSubclassWindow() 
{
	CStatic::PreSubclassWindow();
	
	RECT rt; GetWindowRect(&rt);
	GetParent()->ScreenToClient(&rt);
	// hide the place holder, no not destro it I need it to rerout the messages
	ShowWindow(SW_HIDE);
	// make it on the heap as long  CMyMiniFrm::OnNcDestroy call ''delete this'' 
	// save me to map one more message
	m_minifrm = new CMyMiniFrm();
	m_minifrm->Create( AfxRegisterWndClass(0,0,0),
				"",WS_VISIBLE|WS_CHILD,rt,GetParent()/*of placeholder*/);

	{
		// Initialize dialog bar m_wndMyDialogBar
		if (!m_wndMyDialogBar.Create(m_minifrm, GetDlgCtrlID(),
			CBRS_RIGHT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE,
			CG_ID_VIEW_MYDIALOGBAR))
		{
			TRACE0("Failed to create dialog bar m_wndMyDialogBar\n");
			return;		// fail to create
		}

		m_wndMyDialogBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
		m_minifrm->EnableDocking(CBRS_ALIGN_ANY);
		if(rt.right-rt.left > rt.bottom-rt.top)
			m_minifrm->DockControlBar(&m_wndMyDialogBar,CBRS_ALIGN_LEFT);	
		else
			// dock verically
			m_minifrm->DockControlBar(&m_wndMyDialogBar,CBRS_ALIGN_RIGHT);
		m_minifrm->RecalcLayout();
		//m_minifrm->DockControlBar(&m_wndMyDialogBar);

	}
}

然后,我们还要解决消息传递问题。

 
 
void CStTbar::PreTranslate(MSG* pMsg)
{
	// forward this to the toolbar
	// 
	if(m_wndMyDialogBar.IsWindowVisible())
			m_wndMyDialogBar.OnUpdateCmdUI(m_minifrm,TRUE);
}

这样一个在对话框中产生DialogBar的类基本完成。

然后在要使用DialogBar的对话框中增加一个STATIC控件,定义成和准备当作DialogBar使用的Dialog一样的ID号,再给STATIC控件增加CstTbar型的Contrl变量,就可以使用了。 另外,我们只要为该DialogBar创建一个类,在该类中就可以像操作普通对话框一样在ClassWizard中对各控件进行操作或处理各种消息。

转载于:https://www.cnblogs.com/rogee/archive/2011/03/31/2000465.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值