How to know a dialog is modal or modeless from windows handle?

abc abc 346 Reputation points


In a dll I have child dialog with button control. In main application I am using this child dialog from dll in modal dialog or modeless dialog. The parent of modal or modeless dialog is modal dialog.

When clicking button control in dll I need to launch modal dialog.

I want to prevent the user from dismissing/closing the super parent dialog(first), when both the parent dialog(second) and the last modal dialog(third) are open. To handle this I need to disable super parent dialog(first) before launching last modal dialog(third). I need to disable super parent dialog only if parent of last modal dialog is modeless.

How to check a dialog is modal or modeless from the handle?

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
2,753 questions
No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 68,676 Reputation points

    There is no real way
    See : How can I tell whether a window is modal?

  2. RLWA32 30,101 Reputation points

    Assuming that the question is speaking to the Windows API and not MFC -

    When the modal first dialog creates the second dialog it can pass a parameter to indicate whether the second dialog is modal or modeless. If the second dialog is to be modal use DialogBoxParam to pass the parameter. If the second dialog is to be modeless, use CreateDialogParam to pass the parameter. The second dialog stores the value of the parameter when it handles its WM_INITDIALOG message.

    The second dialog can then determine if it was created as modal or modeless. If modeless, it can disable its owner window before creating the third modal dialog and enable it when the third modal dialog returns.

    In any event, the dialog procedure for a modal dialog should close the dialog using EndDialog while a modeless dialog would use DestroyWindow. So unless you are using the same dialog procedure for both modal and modeless dialogs, they would be specifically written for either modal or modeless operation.