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