Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if window is "Always on top"?

Tags:

c++

c

winapi

In my useful hotkeys program, i have a global hotkey which sets your current foreground window to be Topmost/Not topmost by calling

SetWindowPos(hwnd, HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
SetWindowPos(hwnd, HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

at the moment i have to have two separate hotkeys, Win+Z to set window to TOPMOST anjd Win+X to set window to NOTOPMOST.

I can't find a function in MSDN which lets you check the windows z order.. i was hoping for something like GetWindowOrder, but there isn't. I also tried checking the windows ex flags like so:

dwExStyles & WS_EX_TOPMOST

but it seems that flag isn't never changed, it just tells the window to set itself topmost when its first created.

Is there a function to check this?

like image 221
Kaije Avatar asked Mar 19 '11 18:03

Kaije


People also ask

How do I make sure windows are always on top?

To make the active window always on top, press Ctrl + Spacebar (or the keyboard shortcut you assigned). Press the keyboard shortcut again to disable “always on top” for the active window.

Can you pin a window on top?

In order to pin a window, right-click on the icon in your tray again and enter Pin Mode. Your cursor will change to a pin – click on the title bar of the window you want to always keep on top, and a pin will appear on that bar. It'll be the color you set in the options menu earlier.

How do I pin a window on my desktop?

Select Start , scroll to the app you want to pin, then press and hold (or right-click) the app. Select More > Pin to taskbar. If the app is already open on the desktop, press and hold (or right click) the app's taskbar icon, and then select Pin to taskbar.

How do I keep a window on top Windows 7?

Always On Top forces selected windows to stay on top. It's free, it's easy, and it works. I tested it on my Windows 7 x64 machine. Just run the utility, click the window you want to keep on top, then press Ctrl-Space.


1 Answers

I think you can do this:

DWORD dwExStyle = ::GetWindowLong(m_hWnd, GWL_EXSTYLE);

if ((dwExStyle & WS_EX_TOPMOST) != 0)
{
    // do stuff
}

Here's the MSDN link - http://msdn.microsoft.com/en-us/library/ms633584(VS.85).aspx

And here's the MSDN link to the extended styles - http://msdn.microsoft.com/en-us/library/ff700543(v=VS.85).aspx - topmost is currently listed as "TBD" :)

like image 70
Stuart Avatar answered Oct 26 '22 16:10

Stuart