Click here to Skip to main content
13,050,429 members (132,458 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 15 Oct 2011

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.
    ... // The window is not topmost.

This is because SetWindowsPos()gives WS_EX_TOPMOST extended style to your window when it makes the window topmost.


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


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 */

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

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