MFC Controls: Dialog Bars |
|
Overview |
A dialog bar is an object of the family of Control Bars. These are objects used to complete an interface when the frame needs extra real estate to carry the desired controls of an application. One of the main justifications of control bars is that the user can display or hide them at will. A dialog bar is a sort of intermediary between a dialog box and a toolbar. Like a dialog box or a toolbar, a dialog bar is mainly used as a container or host of other controls. |
Like a dialog box, a dialog bar is created from a dialog-based resource. To create a dialog box, toolbar, you can display the Add Resource dialog box, expand the Dialog node and double-click Dialog bar. This would add a border-less dialog resource to your application. You have two options: you can keep the dialog bar as is or you can derive a class from it. Keeping the dialog bar as created is probably easier because it is ready to be recognized by the other classes, namely the frame and the document, of your application. To add a dialog bar to your project, in the frame header class, you can declare a CDialogBar variable. To display and attach it to your interface, you can programmatically create it in the OnCreate() event of your frame class using one of the overloaded CDialog::Create() method: virtual BOOL Create( CWnd* pParentWnd, LPCTSTR lpszTemplateName, UINT nStyle, UINT nID ); virtual BOOL Create( CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID );
|
Practical Learning: Introducing |
void CExoBarView::OnBnClickedSubmitBtn() { // TODO: Add your control notification handler code here AfxMessageBox("Thank you for your consideration\n" "Your application has been submitted to Human Resources\n" "Once we have reviewed, we will contact you"); }
// MainFrm.h : interface of the CMainFrame class // #pragma once class CMainFrame : public CMDIFrameWnd { DECLARE_DYNAMIC(CMainFrame) public: CMainFrame(); // Attributes public: // Operations public: // Overrides public: virtual BOOL PreCreateWindow(CREATESTRUCT& cs); // Implementation public: virtual ~CMainFrame(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // control bar embedded members CStatusBar m_wndStatusBar; CToolBar m_wndToolBar; CDialogBar m_wndToolbox; // Generated message map functions protected: afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); DECLARE_MESSAGE_MAP() };
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } m_wndToolBar.SetWindowText("Standard"); // Create the dialog bar using one of its Create() methods if( !m_wndToolbox.Create(this, IDD_TOOLBOX, CBRS_LEFT | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY, IDD_TOOLBOX) ) { TRACE0(_T("Failed to create the toolbox\n")); return -1; } // When the dialog bar is undocked, display a caption on its title bar m_wndToolbox.SetWindowText("Toolbox"); if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } // TODO: Delete these three lines if you don't want the toolbar to be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); // Allow the dialog bar to be dockable on the left or the right of the frame m_wndToolbox.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); DockControlBar(&m_wndToolbox); return 0; }
|
Copyright © 2004-2010 FunctionX, Inc. |
|