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

abc abc 351 Reputation points
2020-12-04T08:52:13.007+00:00

Hi,

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?

C++
C++
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.
3,511 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 81,356 Reputation points
    2020-12-04T09:15:28.4+00:00

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

    0 comments No comments

  2. RLWA32 39,906 Reputation points
    2020-12-04T12:41:36.1+00:00

    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.

    0 comments No comments