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

匿名 (未验证) 提交于 2019-12-03 01:29:01

问题:

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?

回答1:

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



回答2:

You are looking for GetWindow():

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!