Use the dialog box in the dock pane for Visual Design

Source: Internet
Author: User

Abstract:This article describes how to use a Dialog box in Dockable Pane to implement visual design. A Dialog box (Dialog) is filled in the dock Pane as a subwindow, in this way, you can visually design the window through the Visual Studio dialog box resource editing function, and easily implement the message processing program of the control.

Keywords:Dockable Pane, Dialog, Visual Design

 

1. Use the dock pane to develop the user interface

In many programs, the dock pane is used as an important part of the user interface. The most familiar example is the most commonly used Visual Studio. Since VS2008 SP1 and VS2010, the new version of the MFC framework has provided a series of classes to implement such functions, of which the most noteworthy is the CDockablePane class.

The CDockablePane class represents a dock pane. Its usage can be learned by reading the source code automatically generated by the Visual Studio "MFC Application Wizard. The process for creating a docked pane is roughly divided into five steps:

(1) define a class that inherits from CDockablePane to implement specific functions.

(2) define the member variables of the above Type in CMainFrame.

(3) Call the Create FUNCTION creation pane of CDockablePane in the OnCreate function of CMainFrame.

(4) Call the EnableDocking function of CDockablePane to configure the dock location.

(5) Call the DockPane function of CMainFrame to dock this pane.

For more information, see the code generated by Visual Studio.

However, Visual Studio does not provide Visual design support for the dock pane. However, if necessary, the dialog box function can be used for indirect implementation.

Ii. Design Ideas

In accordance with the easy-to-use and reusable code design principles, you need to consider the following aspects:

(1) A User class should be provided to inherit and use (CDockableForm). To design the CDockableForm class to add control-related variables and event handlers in the dialog box editing view, the CDockableForm class should be a subclass of the CDialog class.

(2) When a user creates such objects, the CDockablePane class objects should also be created. This class provides a Create function, which should complete the creation process of the dock pane and dialog box at the same time.

(3) the dialog box should be full and displayed with the hidden and hidden tabs. In this case, you need to set the dialog box as a child window of the dock pane, add a class (CDockablePaneAsContainer) inherited from CDockablePane, and adjust the position of the dialog box in its WM_SIZE message processing function.

(4) The Destruction dialog box should be destroyed at the same time when the pane can be docked. The destroy dialog box in the WM_DESTROY message processing function in the dashboard can be docked.

(5) The CDockablePane class should provide a member function so that users can access its CDockablePane member to implement its function of stopping in the main frame window (CMainFrame.

As described above, the design class.

Figure 2-1 class chart

For the implementation code of the CDockableForm class and CDockablePaneAsContainter class, see Appendix 1-4.

There are four steps:

(1) Create and edit dialog box resources, add a dialog box class, and select the CDialog class as the base class.

(2) Add DockableForm to the project. h and DockableForm. cpp (see appendix 5). the header file of the dialog box class contains DockableForm. h. Change the base class of the dialog box class to CDockableForm, replace the header file of the dialog box class and all CDialog in the source code file with CDockableForm, and modify the constructor of the dialog box class, because the constructor of the CDockableForm class is different from that of the CDialog class.

(3) Add a member of the class generated in step 2 to the CMainFrame class, and call the Create function of the member to Create the dock pane in its OnCreate function, call the GetDockablePane method to obtain the reference of its dock pane to implement the dock function.

For examples, see Appendix 5.

Appendix

1. The declaration code of the CDockableForm class.

class CDockablePaneAsContainer : public CDockablePane{public:CDockablePaneAsContainer(CDialog* pDialog) : m_pDialog(pDialog) { }private:CDialog* m_pDialog;public:DECLARE_MESSAGE_MAP()afx_msg void OnSize(UINT nType, int cx, int cy);afx_msg void OnDestroy();};

2. Implementation Code of CDockableForm.

Round (round, CDockablePane) ON_WM_SIZE () round () END_MESSAGE_MAP () void round: OnSize (UINT nType, int cx, int cy) {CDockablePane: OnSize (nType, cx, cy); // TODO: add the message processing program code here if (m_pDialog-& gt; GetSafeHwnd () {CRect rc; GetClientRect (rc); m_pDialog-& gt; moveWindow (rc) ;}} void CDockablePaneAsContainer: OnDestroy () {CDockablePane: OnDestroy (); // TODO: add the message processing program code m_pDialog-& gt; destroyWindow ();}

3. CDockableForm class declaration code.

class CDockableForm : public CDialog{public:CDockableForm(UINT nIDTemplate);     virtual BOOL Create(LPCTSTR lpszCaption, CWnd* pParentWnd,const RECT& rect,BOOL bHasGripper,UINT nID, DWORD dwStyle,DWORD dwTabbedStyle = AFX_CBRS_REGULAR_TABS,DWORD dwControlBarStyle = AFX_DEFAULT_DOCKING_PANE_STYLE,CCreateContext* pContext = NULL);CDockablePane& GetDockablePane() { return m_wndPane; }private:  CDockablePaneAsContainer m_wndPane;};

4. Implementation Code of CDockablePaneAsContainer.

CDockableForm::CDockableForm(UINT nIDTemplate): CDialog(nIDTemplate, &m_wndPane), m_wndPane(this){}BOOL CDockableForm::Create(LPCTSTR lpszCaption, CWnd *pParentWnd, const RECT &rect, BOOL bHasGripper, UINT nID, DWORD dwStyle, DWORD dwTabbedStyle, DWORD dwControlBarStyle, CCreateContext *pContext){m_wndPane.Create(lpszCaption, pParentWnd, rect, bHasGripper, nID, dwStyle, dwTabbedStyle, dwControlBarStyle, pContext);CDialog::Create(m_nIDHelp, &m_wndPane);SetParent(&m_wndPane);ShowWindow(SW_SHOW);return TRUE;}

5. Sample Code:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.