How to design MDI window styles

xiaoxiao2021-03-06  45

Multi-Document Interface (MDI) is a new Windows window style. Support in a lot of windows in an application support, and can be dragged between different windows. How to design a MDI interface different from VC Wizard automatically generate interface style? The following documents are one of many solutions.

First, how to go down the starting sub-window in a multi-document interface

Under the multi-document interface, automatically generate a new sub-window, and an actual application system is often regenerated into a new window after operation. In order to remove the started sub-window, you can analyze the statement of the command line at the application file.

CCommandLineInfo cmdinfo;

Parsecommandline (CMDInfo);

After adding:

CMDINFO.M_NSHELLCOMMAND = ccommandlineinfo :: filenothing;

After getting off the sub-window, there is only the main frame window. Because in a multi-document interface, the system generates two menus: one is the user's menu, the other is the system main frame menu. Usually the user works in the user menu. To ensure that the menu interface is constant, you can modify the main frame menu resource so that it is consistent with the user menu.

Second, modify the window title bar

By default, the document name shown in the window title bar is the file name. To display a long string in the title bar without modifying the file name, you can convert the project workspace to the Resource View panel, select the string table, double-click the idR_mainframe item in String Table, and display one in the CAPTION. String XX YY ..., modify the first parameter to the user you want to see the main window title.

Third, modify the main frame window, sub-window and its display properties

The main window and sub-window can be modified by overlying member function precomreateWindow of CWND. The PrecreateWindow function is called before the creation window, the function is: Virtual Bool PrecreateWindow (CreateStruct CS). If you want to override the PrecreateWindow function, you can modify the CreateStruct structure before you create a window to replace default parameters. CreateStruct Structure storage window features, such as window coordinates, style, etc., you can define new window style.

To modify the main frame window, add the content to be modified in the following member functions of Mainfrm.cpp. E.g:

Bool CMAINFRAME :: PrecreateWindow (CreateStruct & Cs)

{

// Modify the window class or style by modifying the CreateStruct structure

/ / Define the height, width of the new window

Cs.cx = 450;

CS.CY = 300;

/ / Define the new window style to remove the main window name and maximize the button

CS.Style = WS_POPWINDO;

Return CFrameWnd :: PrecreateWindow (CS);

}

The operation of the custom sub-window is the same as the main window described above, and the following can be added to Childfrm.cpp:

Bool Cchildframe :: PrecreateWindow (CreateStruct & Cs)

{

// Modify the window class or style by modifying the CreateStruct structure

Return CmdichildWnd :: PrecreateWindow (CS);

}

To modify the display nature of the view window, add the following statement in the following member function of the view file XXView.cpp:

Bool XXView :: PrecreateWindow (CreateStruct & Cs)

{

// increased statement

Cs.lpszclass = afxregisterWndClass (cs_hredraw | cs_vredraw, 0, (hbrush) :: getStockObject (White_brush), 0);

Return CscrollView :: PrecreateWindow (CS);

}

Among them, the parameter PSZClass of CS is used to store the Windows window class name. Want to register a Windows window

Class, you must call global functions AFXREGISTERWNDCLASS. This function prototype is:

LPCTSTR AFXAPI AFXREGISTERWNDCLASS (uint nclassstyle, hcrusor hcursor = 0, Hbrush HbRBackground = 0, Hicon Hicon = 0)

The above parameters are used to define styles, and their meanings are cursor resource handles, background resource handles, and icon resource handles. The role of the above added statement is: change the window size heavy draft window, not display cursor icon, set white background.

Fourth, the rolling of the window

The scroll window can be implemented using CScrollView instead of the CView class. At this point, the system generates an onInitialUpdate () member function:

Void cmyscrollview :: onInitialupdate ()

{

CscrollView :: OnIntialUpdate ();

CSIZE SIZETAl;

SizetotAl.cx = sizetotal.cy = 100;

Setscrollsizes (mm_text, sizetotal);

}

Among them, CX and CY are horizontal, vertical components of the scroll window, indicating the horizontal direction of the window, and the vertical direction is less than 100 pixels in units. The horizontal direction scroll bar and the vertical direction scroll bar. By modifying the scroll size, you can change the smallest window of the scroll bar. For example, if "siz ketotal.cx = 600; sizetotal.cy = 800;", a scroll bar will appear when the window size is less than 600 × 800.

Five, window segmentation

This feature can split the window into a plurality of rolling panels, the boundary between the panels is called a split bar, and the split strip can be used to adjust the relative size of each panel. To increase window segmentation, you must modify the main window class. First, add the following code to the header file mainfrm.h of the main window class:

CsplitterWnd m_swnd;

Virtual Bool OncreateClient (LPCReatestruct CS, CCReateContext * PCONText);

Add the definition of the member function on the MAINFRM.CPP:

Bool CMAINFRAME :: OnCreateClient (lpcreateStruct CS, CCReateContext * p context)

{

Return M_SWND.CREATE (this, 2, 2, csize (20, 20), pcontext);

}

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

New Post(0)