Click here to Skip to main content
11,642,600 members (63,934 online)
Click here to Skip to main content

Tagged as

How to determine if your window is topmost.

, 16 Oct 2011 CPOL 14.7K 1
Rate this:
Please Sign up or sign in to vote.
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.

License

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

Share

About the Author

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


You may also be interested in...

Comments and Discussions

 
GeneralReason for my vote of 2 Easy problem Pin
Wyz19-Oct-11 19:43
memberWyz19-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
memberCharles Oppermann17-Oct-11 8:45 
There may be multiple windows with the WS_EX_TOPMOST style bit set, so don't use the presence or non-presence of this flag to determine whether or not your window is visible.
/* Charles Oppermann */
http://weblogs.asp.net/chuckop

GeneralRe: But being top-most is no guarantee that the window is visible to the user Pin
Tsuda Kageyu17-Oct-11 9:21
memberTsuda Kageyu17-Oct-11 9:21 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150731.1 | Last Updated 16 Oct 2011
Article Copyright 2011 by Tsuda Kageyu
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid