The program operation effect chart is as follows:
In the MAINFRM program to join the DialogBar is very convenient, we all know, DialogBar has a toolbar unmatched superiority, it can place control, easy to achieve such as WPS Office navigation function. But how do you implement this navigation function in a dialog based program? This article proposes the solution to this question, will perplex oneself very long the question solution method and everybody shares together.
As we all know, CDialogBar cannot be produced in the dialog program because there is no mainfrm in dialog, so I have a class CMiniFrameWnd from 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
}
Then, we can generate our own build CDialog class from CStatic, where the code to create CDialogBar is as follows
void Csttbar::P resubclasswindow ()
{
CStatic::P Resubclasswindow ();
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 in 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_wndmydialo Gbar\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_alig N_left);
Else
//Dock verically
M_minifrm->dockcontrolbar (&m_wndmydialogbar,cbrs_align_right); br> m_minifrm->recalclayout ();
//m_minifrm->dockcontrolbar (&m_wndmydialogbar);
}
}
Then, we will also resolve the messaging issue.
void CStTbar::PreTranslate(MSG* pMsg)
{
// forward this to the toolbar
//
if(m_wndMyDialogBar.IsWindowVisible())
m_wndMyDialogBar.OnUpdateCmdUI(m_minifrm,TRUE);
}
Such a class that generates DialogBar in a dialog box is basically complete.
Then add a static control in the dialog box that you want to use DialogBar, define it as the dialog ID number that you would like to use as DialogBar, and then add the Csttbar-type Contrl variable to the static control, and you can use it.
In addition, we simply create a class for the DialogBar, in which you can manipulate or process various messages in ClassWizard as you would a normal dialog box.
This article supporting source code