views:

1732

answers:

4

Hi,

I create a window with CreateWindow() and show it with ShowWindow(). But the parent window on which this was created should be disabled until user returns from this window, i.e. it should simulate modal dialog box. Any help is appreciated.

Thanks

+2  A: 

You need to consider what it means to be a modal window - basically, the window's parent is disabled. The only automatic way of doing this (that I am aware of) is to call DialogBox() to create a modal dialog box. However, since you want to use CreateWindow(), then all that you need to do is to manually disable the parent window yourself.

Ideally, it would be better to go the dialog box route (since the OS knows exactly what must be done in order to create a modal window), but I suppose this option is there if you must use it.

Andy
+4  A: 

Modality, part 1: UI-modality vs code-modality explains how to do this, and why you might not want to.

jeffm
As a rule I up vote all Old New Thing references.
Aardvark
A: 

Make sure you set the hwndParent in CreateWindow and use EnableWindow(false) to disable the parent after showing the pop up window. Then enable the parent with EnableWindow(true) after the pop up window has been closed.

Mo Flanagan
A: 

You could also run a "secondary message loop" which keeps the parent window inactive till your work with the "modal" dialog is finished.

Vulcan Eager