Tech Support > Microsoft Windows > Development Resources > Is this Dialog Modal or Non-Modal?
Is this Dialog Modal or Non-Modal?
Posted by Larry Lindstrom on February 14th, 2006


Hi Folks:

Is there a method for a dialogproc is tell if
it is displaying a modal or modeless dialog?

Thanks
Larry

Posted by Lucian Wischik on February 14th, 2006


Larry Lindstrom <nobody@aracnet.com> wrote:
(there might be some neat thing that answers your question directly,
but I don't know it).

I think you should explain more about what you're doing, and how you
think this answer would help you accomplish it. I suspect there are
different ways to achieve the same end.

Your question amounts to: "is this dialog-box running from the
message-loop that I myself wrote in my WinMain, or is it running in
the context of a message-loop below that which resides in the system's
DialogBox API routine?" (the answer could I suppose be found by
walking the callstack with ToolHelp but that's horrible).

Your question could also amount to this: "is my window topmost while
all other windows in my app are disabled?" (That's because, for
instance, in VCL, when it displays a model dialog box, it actually
emulates modality itself in its own message-loop, first by disabling
all other top-level windows in the app, then by setting a global flag
and creating the window modelelessly).

--
Lucian

Posted by Larry Lindstrom on February 15th, 2006


Lucian Wischik wrote:
Thanks Lucian:

I have a set of dialogs that will be used to input
data. This is the modal use of the dialogs.

Before the dialogs are used for input, the purchaser
of the program selects which dialogs are to be used.
This runs the dialogs modelessly. A combobox has the
names, user friendly names, of the dialogs where they
can be selected. The user can right click the combo's
edit box or list to bring up the dialog under the cursor
to see if it is the one they want. The dialog will
disappear if they right button up while the cursor is in
the combo box, otherwise the dialog will remain displayed
until one of the buttons used to close it, "finish" or
"cancel", are pressed. These buttons call EndDialog() is
used to destroy modal dialogs, DestroyWindow() for modeless.

As you can imagine, this is a complex piece of code,
but it's working well.

The parameter passed to the DialogBoxParam or
CreateDialogParam is a structure, I've added a flag to
tell the dialog proc if it was called modeal or modeless.
That will work fine, but I was wondering if there was an
API that would allow the dialog proc to find this out for
itself.

I appreciate your response.

Thanks
Larry

Posted by Kellie Fitton on February 15th, 2006


Hi,

A modal dialogBox sets the parent window to disabled state,
you can use the API IsWindowEnabled() and check the returned
value, the API returns FALSE for modal dialog and TRUE otherWise.
if you don't have a parent window you can create a window and
set it to be the parent of any dialogBox by using the function
SetParent().

http://msdn.microsoft.com/library/de...dowenabled.asp

http://msdn.microsoft.com/library/de.../setparent.asp

Hope these information helps,

Kellie.


Similar Posts