Hide / Minimize dialog on startup

Have you ever tried to minimize a dialog during the startup of a dialog based application? The problem is 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 got such a requriment? 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.

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

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

CDialogBasedDlg dlg;
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 do haven’t to worry about such things.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: