Chapter 7 creating MDI apps

Source: Internet
Author: User

 

Creating MDI apps

Before multi-SDI, the MDI was available. wtl provides a series of related classes based on the cframewindowimplbase base class, which makes it especially easy for programmers to compile the MDI application. Figure9 shows the MDI window architecture of wtl.

Figure 9: MDI windowing hierarchy of wtl

 

The cmdiwwindow class is the interface class of the MDI application. It inherits from the cwindow base class and adds two data members to save the window handle of the MDI customer zone and the menu handle of the MDI framework respectively:
Class cmdiwindow: Public ATL: cwindow
{
Public:
// Data members
Hwnd m_hwndmdiclient;
Hmenu m_hmenu;
···
}
This class also encapsulates the sending and processing requests of the wm_mdixxx message family specific to the MDI window, and provides related functions to programmers in the form of member functions. The member functions are named mdixxx ().
The MDI application consists of a window framework, a framework customer area for managing the MDI child window, and an MDI child window (as shown in figure 10)

Figure 10: MDI application consisting of frame, client area, and MDI children

 

To create an MDI subwindow, You Need To derive your own window class from the cmdichild1_wimpl class.
Class cchildframe: Public cmdichild1_wimpl <cchildframe> {

Public:
Declare_frame_wnd_class (null, idr_mdichild)

Chtmlview m_view;

Virtual void onfinalmessage (hwnd/* hwnd */){
Delete this;
}

Begin_msg_map (cchildframe)
Message_handler (wm_create, oncreate)
Chain_msg_map (cmdichild1_wimpl <cchildframe>)
End_msg_map ()

Lresult oncreate (uint, wparam, lparam, bool &){
M_hwndclient = m_view.create (m_hwnd, rcdefault,
_ T ("http://www.microsoft.com "),
Ws_child | ws_visible, ws_ex_clientedge );

Bhandled = false; // Let base class have a crack
Return 1;
}
...
};
The MDI child frame window is very similar to the SDI frame window (the MDI child frame window class is generally named cchildframe ). for example, you can pass the menu resource ID to the declare_frame_wnd_class macro to manage the creation of related resources, as you did in the SDI Framework Window. similarly, we create a view in the wm_create message ing function. however, the difference is that after creating a view, you must set bhandled to false, because we need the MDI child window base class to continue to process the wm_create message.
Lresult cchildframe: oncreate (uint/* umsg */, wparam/* wparam */, lparam/* lparam */, bool & bhandled)
{
Bhandled = false;
···
}
Finally, in the virtual function onfinalmessage (), the MDI sub-framework window class calls its own Delete operator to release related resources.
Void cchildframe: onfinalmessage (hwnd/* hwnd */)
{
Delete this;
}

According to our design, the cmdiframeworkwimpl class serves as the base class for all the MDI Framework Window classes, implementing the MDI framework and the MDI customer zone. The following example:
Class cmainframe: Public cmdiframeworkwimpl <cmainframe> {
Public:
Declare_frame_wnd_class (null, idr_mainframe)
Begin_msg_map (cmainframe)
Message_handler (wm_create, oncreate)
Command_id_handler (id_file_new, onfilenew)
Command_id_handler (id_window_cascade, onwindowcascade)
...
Chain_msg_map (cmdiframeworkwimpl <cmainframe>)
End_msg_map ()

Lresult oncreate (uint, wparam, lparam, bool &)
{

// CREATE command bar window, toolbar and statusbar
...

// Create MDI Client
Createmdiclient ();
M_cmdbar.setmdiclient (m_hwndmdiclient );
...
Return 0;
}

Lresult onfilenew (word, word, hwnd, bool &)
{
// Create MDI child
Cchildframe * pchild = new cchildframe;
Pchild-> createex (m_hwndmdiclient );
Return 0;
}

Lresult onwindowcascade (word, word, hwnd, bool &)
{
Mdicascade ();
Return 0;
}
...
};
In the wm_create message ing function, createmdiclient (), a member function of cmdiframeworkwimpl, is called to create an MDI customer zone and set m_hwndmdiclient data member. the MDI customer zone exists as the parent window of all MDI child frame windows. all MDI subwindows are created in the message processing function onfilenew (). Each MDI subwindow is an instance of the MDI subwindow class and uses the MDI customer zone as its parent window. finally, we create an MDI Framework Window in winmain (), which is similar to SDI.

 

Divide and conquer with Splitters

To be continued...






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.