Hiding a dialog box window

I have written a standard MFC dialog box application that also displays an icon in the taskbar next to the time in the lower right-hand corner of the screen. When the application is started, I do not want to display the dialog box.

What I have done so far is to put a call to ShowWindow( SW_HIDE) in the OnPaint() routine. It works pretty good here but when the application is started, I still see a flicker of the dialog box before it is hidden.

How do I write code so that the dialog box isn't displayed at all when the application is started?
cunninghamAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
chensuConnect With a Mentor Commented:
Put ShowWindow(SW_HIDE) in the OnNcPaint.

ON_WM_NCPAINT()

void CMyDlg::OnNcPaint()
{
    if (m_bHidden)
        this->ShowWindow(SW_HIDE);
     
    CDialog::OnNcPaint();
}
0
 
AlexVirochovskyCommented:
I think, you can create you main
window hidden , start it , hide you
dialog, and after that make you
main window visible.
0
 
mandhjoCommented:
How about calling ShowWindow(SW_Hide) in the OnInitDialog function of your dialog?  Have you tried this?

0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
cunninghamAuthor Commented:
This is not what I want to do. I want to hide the main window so that it is never seen when the application is started. The main window happens to be a dialog box in this case.
0
 
cunninghamAuthor Commented:
I have tried calling ShowWindow(SW_HIDE) in the OnInitDialog() function but this does not work.
0
 
malmqCommented:
You might want to try and override the PreCreateWindow() and make sure the visible style is turned off.
0
 
Gandalf32Commented:
If it is a dialog box, you can uncheck the visible property in the resource editor. Otherwise, put a call to ShowWindow(SW_HIDE) in the OnInitDialog or thePreCreateWindow event.
Another method is to create your application without a main window. Just place the icon in the taskbar, and show the dialog when you want it.
0
 
cunninghamAuthor Commented:
I have tried calling ShowWindow(SW_HIDE) in the OnInitDialog() function but this does not work. Also, I have overridden the PreCreateWindow() routine but this does not work either. In fact, the PreCreateWindow() function does not even get called when the main window is a dialog box. I think this only works in the normal frame/doc/view type of program. I also tried to turn off the visible property of the dialog box in the resource editor but this surprisingly also did not work. I think that something overrides this if it is the main window for the application.

I don't think that you can create an icon in the taskbar without creating a window first. The NOTIFYICONDATA structure that is used to create the icon requires an HWND so that it knows who to send the notification messages to. If this is not the case, please let me know.

Thanks for all of your responses even though I still don't know how to solve this problem.
0
 
Gandalf32Commented:
Try calling the function from OnInitDialog, and then returning FALSE from OnInitDialog.
0
 
cunninghamAuthor Commented:
I have tried calling ShowWindow(SW_HIDE) in the OnInitDialog() function and returning FALSE, but this also does not work.
0
 
cunninghamAuthor Commented:
Thanks. This works better than putting it in OnPaint().
0
All Courses

From novice to tech pro — start learning today.