Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

How to determine if your window is topmost.

, 16 Oct 2011
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 the MSX 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, the countryside of Japan.
 
I'm an official member of WTL Team and in charge of the maintenance of the NuGet package.

Comments and Discussions

 
GeneralReason for my vote of 2 Easy problem PinmemberWyz19-Oct-11 19:43 
SuggestionBut being top-most is no guarantee that the window is visible to the user PinmemberCharles Oppermann17-Oct-11 8:45 
GeneralRe: But being top-most is no guarantee that the window is visible to the user PinmemberTsuda 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 | Mobile
Web04 | 2.8.140922.1 | Last Updated 16 Oct 2011
Article Copyright 2011 by Tsuda Kageyu
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid