How to make a modeless dialog always on top within the app

后端 未结 1 718
星月不相逢
星月不相逢 2021-01-24 00:28

I have a modeless popup dialog in my app. I want to make it topmost only within the app it belongs to, not always topmost on the desktop.

I have tried to set the first p

相关标签:
1条回答
  • 2021-01-24 00:59

    Yes HWND_TOPMOST is a very bad user experience, so I will commend you for not taking the easy way out and trying to flip this switch.

    The key to getting a dialog to appear on top of other windows is setting its owner. (Note that in Win32, an owner is distinct from a parent window, although the terms are often confusing.) All dialogs have an owner, and dialogs always stay on top of their owner.

    So when you create the modeless dialog (e.g. using the CreateDialog function), make sure to specify the handle to your application's main window as its owner. Confusingly, the parameter is named hwndParent, but it actually specifies the owner window.

    0 讨论(0)
提交回复
热议问题