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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I think, you can create you main
window hidden , start it , hide you
dialog, and after that make you
main window visible.
How about calling ShowWindow(SW_Hide) in the OnInitDialog function of your dialog?  Have you tried this?

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.
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

cunninghamAuthor Commented:
I have tried calling ShowWindow(SW_HIDE) in the OnInitDialog() function but this does not work.
You might want to try and override the PreCreateWindow() and make sure the visible style is turned off.
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.
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.
Try calling the function from OnInitDialog, and then returning FALSE from OnInitDialog.
cunninghamAuthor Commented:
I have tried calling ShowWindow(SW_HIDE) in the OnInitDialog() function and returning FALSE, but this also does not work.
Put ShowWindow(SW_HIDE) in the OnNcPaint.


void CMyDlg::OnNcPaint()
    if (m_bHidden)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cunninghamAuthor Commented:
Thanks. This works better than putting it in OnPaint().
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.