Search code examples
winapidialogwin32gui

Win32 How to bring a modeless dialog box to the top


I have a set of modeless dialog boxes open, but I can't for the life of me click on one of them get it to appear in the foreground. It gets focus, but the dialog boxes forever remain in the order on the screen that they were created. The last one created is always in the foreground, obscuring (or partially obscuring) the others.

I have tried:

  • SetActiveWindow(hDlg);
  • SetForegroundWindow(hDlg);
  • SwitchToThisWindow(hDlg, FALSE);

in response to a WM_LBUTTONUP message, but though they get called they do nothing. I have tried different configurations in the dialog box properties like playing with the 'SetForground' or 'Topmost' parameters and they do nothing.

Am I trying to do an impossible task?


Solution

  • What is causing this is window ownership. An owned window is always shown above its owner. This is described in the documentation.

    Clearly you have ownership relationships between your modeless dialogs. You can resolve this by making each of the modeless dialogs be owned by the same window.

    Exactly how you do about controlling ownership depends on how you are creating these dialogs. If you are using CreateDialog then the third parameter is used to specify the dialog's owner.