In MFC, the view pattern (including the size of the window) cannot be set by the PreCreateWindow function

Source: Internet
Author: User

Development environment: VS2010

When developing a single-document-based MFC project, I need to set the size of the frame when the program is initialized, and set CS in CMainFrame::P Recreatewindow (createstruct& CS), including the style and size of the frame window.

The following is the code that sets the frame window to 100 and 300 in length and width:

1BOOL CMainFrame::P Recreatewindow (createstruct&CS)2 {3       if(!CFrameWnd::P Recreatewindow (CS))4       {5           returnFALSE;6       }7 8Cs.style &= ~ws_overlapped9Cs.cy = -;TenCs.cx = -; One  A       returnTRUE; -}
View Code

  But the actual operation can not change the size of the frame, the user gave a bit of reason and solution:

Because VS2010 will write some information to the registry, this is not the same as the previous vs2005,vs2008 (except SP1), and the default SDI and MDI are some things with BCG.
You want to modify the window size, you can directly in the App class InitInstance ShowWindow (); UpdateWindow () Before modifying the window size, for example M_pmainwnd->movewindow (CRect (+, +, +), FALSE);

My approach is to first invoke cleanstate () when initializing an instance of the app class, clear the registry state information, and then set the window size and style in the framework class, as follows:

1 int cimagequality02app::exitinstance () 2 {3//  TODO: Add private code here and/or call base class 4  afxoleterm (FALSE); 5 cleanstate (); // clears the state information that the program writes in the registry 6 7 return cwinappex::exitinstance (); 8 }      
View Code
1BOOL CMainFrame::P Recreatewindow (createstruct&CS)2 {3     if( !CFrameWndEx::P Recreatewindow (CS))4       returnFALSE;5     //TODO: Here by modifying6     //CREATESTRUCT cs To modify a window class or style7Cs.cx = -;8Cs.cy = -;9Cs.lpszclass = AfxRegisterWndClass (0);Ten  One     returnTRUE; A}
View Code

Citation Source: http://blog.sina.com.cn/s/blog_62f521600100ml2l.html

http://hyhvi.iteye.com/blog/1513942

In MFC, the view pattern (including the size of the window) cannot be set by the PreCreateWindow function

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.