在对话框程序中插入DialogBar,在对话框程序中插入DialogBar
【 tulaoshi.com - C语言心得技巧 】
在对话框程序中插入DialogBar
作者:徐建鹏
BOOL CMyMiniFrm::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) {// pass those up in the dialog to leave the OnUpdateUI mechanism to flowBOOL br = GetParent()->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);// leave the default proc to handles the tooltip updating mechanismCMiniFrameWnd::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 messagesShowWindow(SW_HIDE);// make it on the heap as long CMyMiniFrm::OnNcDestroy call ''delete this'' // save me to map one more messagem_minifrm = new CMyMiniFrm();m_minifrm->Create( AfxRegisterWndClass(0,0,0),"",WS_VISIBLE|WS_CHILD,rt,GetParent()/*of placeholder*/);{// Initialize dialog bar m_wndMyDialogBarif (!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_wndMyDialogBarn");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 vericallym_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创建一个类,在该类中就可以像操作普通对话框一样在ClassWizard中对各控件进行操作或处理各种消息。
来源:http://www.tulaoshi.com/n/20160129/1483673.html
看过《在对话框程序中插入DialogBar》的人还看了以下文章 更多>>