Click here to Skip to main content
13,195,564 members (63,105 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


17 bookmarked
Posted 8 Apr 2009

Hide / Minimize a Dialog on Startup

, 8 Apr 2009
Rate this:
Please Sign up or sign in to vote.
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:

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

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

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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
Singapore Singapore
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralThank You Pin
thanatos_mx5-Sep-14 8:36
memberthanatos_mx5-Sep-14 8:36 
Generala question Pin
f.s.j8-Apr-09 15:53
memberf.s.j8-Apr-09 15:53 
GeneralRe: a question Pin
Naveen8-Apr-09 17:49
mvpNaveen8-Apr-09 17:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171019.1 | Last Updated 8 Apr 2009
Article Copyright 2009 by Naveen
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid