How to simulate the window form of Word

Source: Internet
Author: User

How to simulate the window form of Word

Important: I will post on cchildframe.

1. Use the Wizard to generate a multi-document application testmdi and generate the following classes:

Caboutdlg, cchildframe, cmainframe, cte1_diapp, cte1_didoc, cte1_diview
2. Modify ctestmdiapp: initinstance (): pmainframe-> showwindow (sw_hide );
3. Modify cchildframe: First Replace the base class with cframewnd, and then move the Code related to creating the toolbar status bar in cmainframe to cchildframe. To highlight the key points,

I only list the changed code. As follows:
// Childfrm. h
Class cchildframe: Public cframewnd
{
Protected: // control bar embedded members
Cstatusbar m_wndstatusbar;
Ctoolbar m_wndtoolbar;
Afx_msg int oncreate (maid );
// {Afx_msg (cchildframe)
Afx_msg void onclose ();
//} Afx_msg
};

// Childfrm. cpp
Implement_dyncreate (cchildframe, cframewnd)

Begin_message_map (cchildframe, cframewnd)
// {Afx_msg_map (cchildframe)
On_wm_create ()
On_wm_close ()
//} Afx_msg_map
End_message_map ()

Static uint indicators [] =
{
Id_separator, // status line indicator
Id_indicator_caps,
Id_indicator_num,
Id_indicator_scrl,
};

Bool cchildframe: precreatewindow (createstruct & CS)
{
If (! Cframewnd: precreatewindow (CS ))
Return false;

Return true;
}
//////////////////////////////////////// /////////////////////////////////////
// Cchildframe message handlers
Int cchildframe: oncreate (maid)
{
If (cframewnd: oncreate (lpcreatestruct) =-1)
Return-1;
 
If (! M_wndtoolbar.createex (this, tbstyle_flat, ws_child | ws_visible | cbrs_top
| Cbrs_gripper | cbrs_tooltips | cbrs_flyby | cbrs_size_dynamic) |
! M_wndtoolbar.loadtoolbar (idr_mainframe ))
{
Trace0 ("failed to create toolbar/N ");
Return-1; // fail to create
}

If (! M_wndstatusbar.create (this) |
! M_wndstatusbar.setindicators (indicators,
Sizeof (indicators)/sizeof (uint )))
{
Trace0 ("failed to create status bar/N ");
Return-1; // fail to create
}

// Todo: delete these three lines if you don't want the toolbar
// Be dockable
M_wndtoolbar.enabledocking (cbrs_align_any );
Enabledocking (cbrs_align_any );
Dockcontrolbar (& m_wndtoolbar );

Return 0;
}

Void cchildframe: onclose ()
{
Cframewnd: onclose ();
// Afxgetmainwnd ()-> postmessage (wm_command, id_close_child, 0 );
}

Okay, now we can compile it. What, good?
However, you soon discovered that my program was not closed? Yes. The main window is hidden and has not been closed yet. Originally, when all windows are closed, the main window should also be

Disabled. So I chose cchildframe: onclose () and sent a message to the main window to check whether there is a cchildframe window:

Void cchildframe: onclose ()
{
Cframewnd: onclose ();
Afxgetmainwnd ()-> postmessage (wm_command, id_close_child, 0); // id_close_child is a custom message.
}
Accordingly, cmainframe has a function to process the message:
Bool cmainframe: oncommand (wparam, lparam)
{
If (wparam = id_close_child)
{
Checkchildwnd ();
Return true;
}
 
Return cmdiframewnd: oncommand (wparam, lparam );
}

Void cmainframe: checkchildwnd ()
{
Cwinapp * PAPP = afxgetapp ();
Position PS = PAPP-> getfirstdoctemplateposition ();
Assert (PS! = NULL );
Cdoctemplate * pdoctemplate = PAPP-> getnextdoctemplate (PS );
PS = pdoctemplate-> getfirstdocposition ();
If (PS = NULL)
Postmessage (wm_close );
}

Solve the basic problem.

What are the benefits of doing so?
Because multiple views share one toolbar and status bar, it is very painful to update the status bar and toolbar when switching views, especially when different views have different status bars.

Bitter. This step is saved by making such a single document interface.
Of course, there should also be some of its shortcomings. I hope you can send me a letter to inform us of the problems or bugs involved in it.

Lan zhengpeng
Zlan@corp.netease.com

 

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.