Click here to Skip to main content
13,897,577 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 15 Oct 2011
Licenced CPOL

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 

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 | Cookies | Terms of Use | Mobile
Web04 | 2.8.190306.1 | Last Updated 16 Oct 2011
Article Copyright 2011 by Tsuda Kageyu
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid