VC Program Interface multi-mode display

Source: Internet
Author: User
Tags bool resource

Read Xu Jing Week wrote a "program interface multi-mode display implementation", the program has multiple display modes in one application, but the interface is implemented by the SDI MFC document view structure, but the code used is not implemented in MDI's multiple documents/views, and through MSDN I found some implementations of MDI Multi-mode implementation method, dare not to enjoy, share with you.

Using SDI and MDI to implement this multiple-mode display application, the first step is to dynamically load and destroy menus. For SDI applications, implementation is relatively simple, for MDI applications, implementation is a bit of a hassle, but these can be done! Oh, Oh!

First, to destroy the menus produced by the SDI and MDI AppWizard, do not create menus in the first place! Have you seen the "simple and simple MFC"? In the PreCreateWindow function to destroy the menu resources, the other thing to note is that you can not delete the resource ID is idr_mainframe menu resources, this is important, otherwise there will be a lot of MFC assertion errors:

// 对于SDI的 PreCreateWindow
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
   cs.style &= ~FWS_ADDTOTITLE;
   cs.style &= ~( WS_SIZEBOX | WS_MINIMIZEBOX | WS_MAXIMIZEBOX );
   if ( cs.hMenu != NULL )
   {
     DestroyMenu( cs.hMenu );
     cs.hMenu = NULL;
   }
   if( ! CFrameWnd::PreCreateWindow( cs ) )
     return FALSE;
   // TODO: Modify the Window class or styles here by modifying
   // the CREATESTRUCT cs
   return TRUE;
}

Multiple Document start Destroy Menu method:

First, the menu resource with ID idr_mainframe is reserved for the same reason as above. Then remove the menu resource for the MDI child window of the menu, with the type of ID (idr_xxxtype). The reason for this is to avoid resource leaks, (where the leak, I have not checked, the MSDN is such a description), in the MDI window, open the child window, there will be menu switching, these are the MFC code automatically implemented, so we are now the switch to the code to remove the menu.

Overload LoadFrame in CMainFrame
//
Virtual BOOL LoadFrame (UINT nIDResource,
DWORD Dwdefaultstyle = Ws_overlappedwindow | Fws_addtotitle,
cwnd* pParentWnd = null, ccreatecontext* pContext = null);
BOOL Cmainframe::loadframe (UINT nidresource, DWORD Dwdefaultstyle,
cwnd* pParentWnd, ccreatecontext* pContext)
{
Return CFrameWnd::LoadFrame (Nidresource,dwdefaultstyle,
Pparentwnd,pcontext);
}
CMainFrame overload OnCreateClient, implement prohibit menu switching
Virtual BOOL cmainframe::oncreateclient (lpcreatestruct lpcs,
ccreatecontext*/*pcontext*/);
BOOL cmainframe::oncreateclient (Lpcreatestruct lpcs,
ccreatecontext*/*pcontext*/)
{
Return CreateClient (Lpcs,null);
}
Add the following code:
BOOL CMainFrame::P Recreatewindow (createstruct& CS)
{
Cs.style &= ~fws_addtotitle;
Cs.style &= ~ (Ws_sizebox | Ws_minimizebox | Ws_maximizebox);
if (Cs.hmenu!= NULL)
{
DestroyMenu (Cs.hmenu);
Cs.hmenu = NULL;
}
if (! CFrameWnd::P Recreatewindow (CS))
return FALSE;
Todo:modify the Window class or styles here by modifying
The CREATESTRUCT CS
return TRUE;
}

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.