Methods for hiding dialog-based MFC application windows
(recommend this method, very useful)
Many people may create the window, and then use a ShowWindow (Sw_hide) method to hide the window, of course, this can be done to hide the function, but there is a little bit of a point is that the window will be hidden before the blink of a short blink, and the following method can solve this problem:
The following paragraph is commented out in the function of C***app::initinstance ():
c***DLG Dlg;m_pmainwnd= &Dlg;intNresponse =dlg. DoModal ();if(Nresponse = =IDOK) { //Todo:place code here-handle when the dialog is//dismissed with OK}Else if(Nresponse = =IDCANCEL) { //Todo:place code here-handle when the dialog is//dismissed with Cancel}//Since The dialog has been closed and return FALSE so that we exit the//application, rather than start the application ' s message pump.returnFALSE;
Into:
New c***= dlg; return dlg->create (idd_***_dialog);
You can also remove the Visible property of the "More Stytles" property page of the Idd_***_dialog dialog resource. This is the simplest way I think, there is another way to do this is to insert a new dialog box in the Resource menu of the workspace, and then use ClassWizard to create a class that corresponds to it, and the following
New c***= dlg; return dlg->create (idd_***_dialog);
Here the C***dlg and Idd_***_dialog instead of your new dialog box, the principle of the same method as above, just a little trouble.
Ways to hide MFC application windows based on a single document
1) The simplest method is found from the Internet, feasible, easy to use
Cmainframe::activeframe () { nCmdShow= sw_hide; Cframewnd::activateframe (nCmdShow); } C?? app::initstance () { m_pMainWnd-ShowWindow (sw_hide); // UpdateWindow (); }
Because MFC has two steps to display the SDI main window, all must be sw_hide in these two places, otherwise it will flash. Even if the HWND does not have a ws_visible attribute, the HWND can be displayed with ShowWindow (sw_show), so there is a problem with the Vcbear method. The ActiveFrame function here can be added in the ClassWizard.
2) The second method is much more cumbersome
The first step is to change the CMainFrame constructor to the public property (default is protected)
The second step is to comment out the following code in the C***app::initinstance ():
csingledoctemplate*pdoctemplate;pdoctemplate=Newcsingledoctemplate (Idr_mainframe, Runtime_class (Ctesthidedoc), Runtime_class (CMainFrame),//main SDI frame windowRuntime_class (Ctesthideview)); AddDocTemplate (pdoctemplate);//Parse command line to standard shell commands, DDE, File openCCommandLineInfo Cmdinfo; ParseCommandLine (cmdinfo);//Dispatch commands specified on the command lineif(!ProcessShellCommand (cmdinfo))returnFALSE;//the one and only window have been initialized, so show and update it.M_pmainwnd->ShowWindow (sw_show); m_pMainWnd->updatewindow ();
Replace with the following code:
New= ((CMainFrame *) m_pmainwnd),LoadFrame (idr_mainframe); if (bRet) { m_pMainWnd-UpdateWindow ();} Else { if (m_pMainWnd) { delete m_pMainWnd; = NULL;} }
This way the Yi out of the program will not have a main window when running.
Looking at the method of the hidden window above, in addition to using ShowWindow (Sw_hide) method, in fact, the m_pMainWnd pointer in the program to change the face, the original is normal display, instead of display, or use other dialog box or a new type of frame pointer .
My first doubt is that since C***app will have its own thread and message loop mechanism, why is it necessary to have such a framework class CMainFrame as its support? Then I checked the source code found in the C***app class of the run () function there is a paragraph ( About the run function here do not do a detailed explanation, interested can go to see "in Layman's MFC"):
int CWinApp::Run () { if (m_pMainWnd = = NULL && Afxolegetuserctrl () ) { // Not launched/embedding or/automation, but have no main window! TRACE0 ("Warning:m_pmainwnd is NULL in cwinapp::run-quitting application.\n"); afxpostquitmessage (0); } return Cwinthread::run ();}
Hehe, as long as the m_pMainWnd is not NULL, the main thread can be turned up. At this point, all the problems will be solved.
[Go] Hide the dialog-based MFC application window method