How to determine if your window is topmost.






4.38/5 (5 votes)
It's a well known tip how to make your window topmost or "Always on Top".
// Make topmost
::SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
// Revert back
::SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
Well, how can you determine if your window is topmost? You can do it like this:
if (::GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)
... // The window is topmost.
else
... // The window is not topmost.
This is because SetWindowsPos()
gives WS_EX_TOPMOST
extended style to your window when it makes the window topmost.