Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / Win32

How to determine if your window is topmost.

4.38/5 (5 votes)
16 Oct 2011CPOL 37.1K  
It's a well known tip how to make your window topmost or "Always on Top".
C++
// 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:
C++
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)