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
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.