Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Hide / Minimize a Dialog on Startup

0.00/5 (No votes)
8 Apr 2009 1  
How to hide/minimize a dialog on startup

Have you ever tried to minimize a dialog during the startup of a dialog based application? The problem is that in a dialog based application, we will not get the control after the dialog is completely created. Even a call to ShowWindow() from the OnInitDialog() function will not work. So what will we do if we have such a requirement? Well I got a simple technique for doing this by modifying the InitInstance() function of the app class.

The code for creating a dialog in the InitInstance() function will look like this:

C++
CDialogBasedDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();

My idea is to change this code a little as follows:

C++
CDialogBasedDlg dlg;
if(dlg.Create( CDialogBasedDlg::IDD ))
{
   dlg.ShowWindow( SW_HIDE );
   m_pMainWnd = &dlg;
   INT_PTR nResponse = dlg.RunModalLoop();
}

Actually inside the MFC Framework, the DoModal() function calls the CreateDlgIndirect() and then RunModalLoop(). It also handles the tasks such as disabling the parent window etc. In our case, the dialog itself is the parent window so we don't have to worry about such things.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here