CDialogBar in CView
-
I'm new to MFC, and I have a little problem. Is there a way to have a dialog bar on the top of a CView in an MDI app? I have the following code, but the dialog bar doesn't get drawn! It works great if I create the dialog bar on the MainFrm. int MyView::OnCreate(LPCREATESTRUCT lpCreateStruct) { m_pDlgBar = new CDialogBar(); if (!m_pDlgBar) return -1; m_pDlgBar->Create( this, IDD_DLGBAR, WS_CHILD | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY, ID_DIALOGBAR); // I don't really know what this parameter does m_pDlgBar->ShowWindow(SW_SHOWNORMAL); if (CView::OnCreate(lpCreateStruct) == -1) return -1; } Any suggestions? Thanks In Advance. Erik
-
I'm new to MFC, and I have a little problem. Is there a way to have a dialog bar on the top of a CView in an MDI app? I have the following code, but the dialog bar doesn't get drawn! It works great if I create the dialog bar on the MainFrm. int MyView::OnCreate(LPCREATESTRUCT lpCreateStruct) { m_pDlgBar = new CDialogBar(); if (!m_pDlgBar) return -1; m_pDlgBar->Create( this, IDD_DLGBAR, WS_CHILD | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY, ID_DIALOGBAR); // I don't really know what this parameter does m_pDlgBar->ShowWindow(SW_SHOWNORMAL); if (CView::OnCreate(lpCreateStruct) == -1) return -1; } Any suggestions? Thanks In Advance. Erik
You want to add the toolbar (or dialog bar) to the frame insted of the view. You can catch the button messages in the doc, view, or frame. The code below will add a toolbar to the child frame: int CFrameClass::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1) return -1; //Create the toolbar. { EnableDocking(CBRS_ALIGN_ANY); if(!m_wndToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP, IDR_TOOLBAR_DEFECTVIEW) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR_DEFECTVIEW)) { TRACE0("Failed to create toolbar\n"); } else { // TODO: Remove this if you don't want tool tips or a resizeable toolbar m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC); // TODO: Delete these lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar, AFX_IDW_DOCKBAR_RIGHT); } return 0; } Good luck, Jonathan Craig
-
You want to add the toolbar (or dialog bar) to the frame insted of the view. You can catch the button messages in the doc, view, or frame. The code below will add a toolbar to the child frame: int CFrameClass::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1) return -1; //Create the toolbar. { EnableDocking(CBRS_ALIGN_ANY); if(!m_wndToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP, IDR_TOOLBAR_DEFECTVIEW) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR_DEFECTVIEW)) { TRACE0("Failed to create toolbar\n"); } else { // TODO: Remove this if you don't want tool tips or a resizeable toolbar m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC); // TODO: Delete these lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar, AFX_IDW_DOCKBAR_RIGHT); } return 0; } Good luck, Jonathan Craig
-
Thanks! It worked, but how can I get a pointer to the child from the view? Thanks again! Erik
Look up this document in the MSDN or on Microsoft's web site; "Relationships Among MFC Objects". I keep this one tacked to the wall next to my computer. The function you want is CWnd::GetParentFrame(). Remember the view is a child of the frame. Good luck and happy hacking... Jonathan Craig