2008年(909)
分类:
2008-05-06 21:30:33
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创建一个类,在该类中就可以像操作普通对话框一样在ClassWizard中对各控件进行操作或处理各种消息。