A customer had a problem where one of their program's
windows was somehow receiving the
WS_
extended window style, thereby becoming topmost.
The scenario was that they created a popup window with the
EX_
TOPMOST
WS_
extended style,
and subsequently opened a document window.
If they destroyed the popup window before creating the document
window, then everything was fine.
But if they created the document window before destroying the
popup window,
then their main app magically gained the
EX_
TOPMOST
WS_
extended style.
Their investigation revealed that nobody was calling
EX_
TOPMOST
SetWindowLong
with
GWL_
and
EXSTYLE
WS_
.¹
Are there other ways that a window can become topmost?
EX_
TOPMOST
One way that a window can become topmost is if it is created
with the
WS_
extended style.
EX_
TOPMOST
Another way that a window can become topmost is if you
call
SetWindowPos
and pass
HWND_
as the
TOPMOST
hwndInsertAfter
.
Yet another way that a window can become topmost is if you
pass a topmost window as the
hwndInsertAfter
.
Armed with this information, the customer did some more
investigation and reported back:
They found a call to
SetWindowPos
that was
making the window topmost.
Mystery solved!
¹
Not that anybody should be doing that anyway.
The documentation for the
WS_
extended style
says that you shouldn't be manipulating the extended style
bit directly.
"To add or remove this style, use the
EX_
TOPMOST
SetWindowPos
function."