简体   繁体   中英

How to check if window is “Always on top”?

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?

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" :)

You are looking for GetWindow() :

Retrieves a handle to a window that has the specified relationship (Z-Order or owner) to the specified window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM