Free generation of custom sub-windows in MDI mode

zhaozj2021-02-16  47

Free generation of custom sub-windows in MDI mode

This article describes how to delete the document / view structure generated by the MFC AppWinzard project, and create a sub-window interface according to its own actual needs.

The standard setting of the application wizard in the Visual C development system allows the application developer to easily create a variety of DOC / VIEW applications, but during the actual software development process, it always feels compared by the procedure generated by the wizard. Trouble, therefore I hope to transform the code generated by appwinzard, so that the program structure is relatively simple, and the document management is available at the same time. A simple example is to generate your own defined sub-windings in a menu item.

The entire processing process is described below. The result of this example is the designation of the defined view CMYVIEW by the specified menu item IDM_TEST, which is the main processing step to generate a MDI to simultaneously support the TEST project of DOC / VIEW. Remove the default sub-window display, join the window code that calls your own defined. Specific implementation follows:

1. Select New from the FILE menu and use the MFC AppWizard (EXE) option to create a new project, the project is called Test. Select the Multiple Documents option and select Document / View ArchitechTure Support. 2. Remove the following from the member function of CTestApp

CMULTIDEMPLATE * PDOCTEMPLATE;

PDOCTEMPLATE = New CMULTIDOCTEMPLATE

IDR_TESTTYPE,

Runtime_class (ctestdoc),

Runtime_class (cchildframe), // Custom MDI Child Frame

Runtime_class (ctestView));

AddDDOCTemplate (pdoctemplate);

3. Create a custom framework class CMYFRAME :, this class is cmdichildwnd.

4. Enter the resource manager, add formview, IDd_formview, and generate the corresponding view class CMYVIEW, the base class is CFormView.

5. Currently created the frames and views we need, the following work is to connect CMYFrame and CMYVIEW. Add member variables in CMYFrame CMYVIEW * m_pMyView; then add the following in the OnCreate member function:

CRECT RECT; GetClientRect (& Re);

m_pmyview = new cmyview; if (! m_pMyview-> Create (null, null, afx_ws_default_view, rest, this, afx_idw_pane_first, null)

{

Trace0 ("Failed to Create View Window / N);

Return 0;

} // AFX_WS_DEFAULT_VIEW * /

Join in the onsize function

CRECT RECT;

This-> getClientRect (Rect);

M_PMYVIEW -> MoveWindow (Rect.LiD, Rect.top, Rect.width (), Rect.Height (), TRUE;

What needs to be pointed here is to change the constructor of CMYVIEW and CMYFrames to the public type, while overloading the CMYVIEW's Create function. 6. Add the IDM_TEST menu item in the menu IDR_MAINFRAME to enter the resource manager, add the following code in the corresponding processing function:

M_PMYFRAME = New CMYFRAME;

M_PMYFRAME-> Create (null, null, ws_child | ws_visible | ws_overlappedWindow, RectDefault);

m_pmyframe-> showwindow (SW_SHOW);

M_PMYFRAME-> UpdateWindow ();

Of course, M_PMYFRAME must be defined first in CMAINFRAME.

7. Compile operation, select the Test menu item, you can open our defined window, after processing, you can delete the TestDoc. * And ChildFrame. *, TestView. *, All the header files in the source program. To form a simple engineering.

There are a variety of different views that may have a different view in actual work, and each view requires a specified framework. You can specify the type of view after defining the framework, and then create different types according to the specified category in the framework on the framework. view.

Personal view, please criticize. 2002.9.30

转载请注明原文地址:https://www.9cbs.com/read-24978.html

New Post(0)