In-depth analysis of WTL-WTL frame window analysis (6)

xiaoxiao2021-03-06  68

WTL to the package window

The ATL is merely encapsulated a window function and provides a message mapping. In practical applications, various types of windows are required, for example, the frame window corresponding to each interface thread. WTL is based on ATL and provides us with a frame window and other various windows.

In all application types, each interface thread has a frame window (FRAME) and a view. Their concepts are the same as the MFC.

The icon is the inheritance diagram of the window class of the WTL.

The WTL frame window provides us:

Title, window frame, menu, toolbar.

View management, including changes in the size of the frame to synchronize with the frame window.

Provide processing code for menus, toolbars, etc.

Display help information in the status bar and so on.

WTL is usually the client area of ​​the application. It is usually used to present content to customers.

The WTL provided method is to create a frame window in the logic of the interface thread, and the viewing creation is responsible by the Frame Window. The following will be introduced, and the frame window creates views when processing the WM_CREATE message.

If you want to create a frame window, you need:

Depends on your frame window from the CFrameWindowImpl class.

Add Declare_Frame_WND_CLASS, specify the resource ID of the menu and toolbar.

Add message mapping while connecting it to the message mapping of the base class. At the same time, the message processing function is added.

Below is the Statement of the main frame window of an SDI application using ATL / WTL App Wizard.

Class CMAINFRAME: PUBLIC CFRAMEWINDOWIMPL ,

Public CUPDATEUI ,

Public CMessageFilter, Public CIDEHANDLER

{

PUBLIC:

Declare_frame_wnd_class (null, idr_mainframe)

/ / Example of the view of the frame window

CVIEW M_VIEW;

/ / The command tool line of the frame window

CCommandbarctrl m_cmdbar;

Virtual Bool PretranslateMessage (MSG * PMSG);

Virtual bool onidle ();

Begin_UPDATE_UI_MAP (CMAINFRAME)

UPDATE_ELEMENT (ID_View_toolbar, UPDUI_MENUPOPUP)

UPDATE_ELEMENT (ID_View_status_bar, updui_menupopup)

END_UPDATE_UI_MAP ()

Begin_MSG_MAP (CMAINFRAME)

Message_handler (WM_CREATE, ONCREATE)

Command_id_handler (ID_APP_EXIT, ONFILEEXIT)

Command_id_handler (id_file_new, onfilenew)

Command_id_handler (id_view_toolbar, onviewtoolbar)

Command_id_handler (id_view_status_bar, onviousstatusbar)

Command_id_handler (ID_APP_ABOUT, ONAPPABOUT)

CHAIN_MSG_MAP (CUPDATEUI )

CHAIN_MSG_MAP (CFrameWindowImpl )

END_MSG_MAP ()

// Handler Prototypes:

// LResult messageHandler (uint / * umsg * /, wparam / * wparam * /, lparam / * lparam * /,

Bool & / * bhandled * /) // LRESULT CommandHandler (Word / * wnotifycode * /, word / * wid * /, hwnd / * hwndctl * /,

Bool & / * bhand * /)

// LResult notifyHandler (int / * idctrl * /, lpnmhdr / * pnmh * /, bool & / * bhandlex * /)

Lresult oncreate (uint / * umsg * /, wparam / * wparam * /, lpaam / * lparam * /, bool &

/ * bhandled * /);

LResult onfileexit (Word / * Wnotifycode * /, Word / * Wid * /, HWND / * HWNDCTL * /,

Bool & / * bhandled * /);

LResult OnfileNew (Word / * Wnotifycode * /, Word / * Wid * /, HWND / * HWNDCTL * /,

Bool & / * bhandled * /);

Lresult onviewToolbar (Word / * WNOTIFYCODE * /, WORD / * WID * /, HWND / * HWNDCTL * /,

Bool & / * bhandled * /);

LResult OnViewStatusbar (Word / * WnotifyCode * /, Word / * Wid * /, HWnd

/ * hWndctl * /, bool & / * bhandled * /);

LResult onappabout (Word / * WnotifyCode * /, Word / * Wid * /, HWND / * HWNDCTL * /,

Bool & / * bhandled * /);

}

DECLARE_FRAME_WND_CLASS () Macro Specifies a resource ID for the Frame Window, which can be linked through this ID and application resources, such as icons, string tables, menus, and toolbars, and more.

WTL

Usually the display area of ​​the application is divided into two parts. The first is the main frame window including the window title, menu, toolbar, and status bar. Another part is called the part of the view. This part is the customer area, used to present content to the customer.

The view can be anything that contains hwnd. When processing WM_CREATE in the frame window, the HWND handle is planted to the M_HWndClien member of the main window to set the main window.

For example, create an app with ATL / WTL App Wizard, create a dependency, code as follows:

Class Ctestview: Public CWindowImpl

{

PUBLIC:

Declare_Wnd_Class (NULL)

Bool PretranslateMessage (MSG * PMSG);

Begin_msg_map (ctestView)

Message_handler (wm_paint, onpaint)

END_MSG_MAP ()

// Handler Prototypes:

// LResult messageHandler (uint / * umsg * /, wparam / * wparam * /, lparam / * lparam * /,

Bool & / * bhand * /)

// LResult CommandHandler (Word / * Wnotifycode * /, Word / * Wid * /, HWND / * HWNDCTL * /,

Bool & / * bhand * /)

// Lresult NotifyHandler (int / * idctrl * /, lpnmhdr / * pnmh * /, bool & / * bhand * /) LRESULT ONPAINT (UINT / * UMSG * /, WPARAM / * WPARAM * /, LPARAM / * LPARAM * /, BOOL &

/ * bhandled * /);

}

This approach is a window derived from the CWindowImpl.

In the creation function of the main window, the HWND of the view is set to the M_HWndClient member of the main window.

LResult CMAINFRAME :: Oncreate (uint / * umsg * /, wparam / * wparam * /, lparam / * lparam * /,

Bool & / * bhand * /)

{

...

M_hWndClient = m_view.create (m_hwnd, rcdefault, null, ws_child | ws_visible

| Ws_clipsiblings | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE

...

Return 0;

}

The above code is created for the main window.

So far we have

Win32 model begins, understand

Windows interface program package and

WTL message loop mechanism, analyzed WTL in detail. Through our analysis, do you have an in-depth understanding of WTL, and can develop high-quality Windows applications? Don't worry, then we will also explore the skills of developing WTL applications.

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

New Post(0)