Click here to Skip to main content
15,880,796 members
Articles / Desktop Programming / Win32
Tip/Trick

How to determine if your window is topmost.

Rate me:
Please Sign up or sign in to vote.
4.38/5 (5 votes)
16 Oct 2011CPOL 35.9K   2   3
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)


Written By
Software Developer
Japan Japan
In 1985, I got my first computer Casio MX-10, the cheapest one of MSX home computers. Then I began programming in BASIC and assembly language, and have experienced over ten languages from that time on.
Now, my primary languages are C++ and C#. Working for a small company in my home town in a rural area of Japan.


Comments and Discussions

 
GeneralReason for my vote of 2 Easy problem Pin
Wyz19-Oct-11 19:43
Wyz19-Oct-11 19:43 
SuggestionBut being top-most is no guarantee that the window is visible to the user Pin
Charles Oppermann17-Oct-11 8:45
Charles Oppermann17-Oct-11 8:45 
GeneralRe: But being top-most is no guarantee that the window is visible to the user Pin
Tsuda Kageyu17-Oct-11 9:21
Tsuda Kageyu17-Oct-11 9:21 
You are right, but it's a different issue.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.