Get which process/window is actually visible in C#

我与影子孤独终老i 提交于 2019-12-02 04:17:14

问题


I have a list of all open windows, the ones in the windows taskbar. What I want to do is to remove the ones that are not visible from the list.

What I mean is, if a window is hidden by another one, it should not be in my list.

I've been searching google for the past two days without success...

Any ideas?

PS: I can get the location and size of each process, so getting the last time a process was used/idle time would work too...


回答1:


You need to use regions, what's still visible of the window can be a complex set of rectangles. Start with the window you want to check, GetWindowRect and CreateRectRegion to create a region for the window rectangle.

Call GetWindow() in a loop, passing GW_HWNDPREV. Which returns the previous window in the Z-order so it could overlap. GetWindowRect() to get its rectangle, CreateRectRegion() and combine that with the original window region using CombineRgn() with RGN_DIFF.

When GetWindow returns NULL you've found all possible overlapping windows. Use GetRgnBox to check if there's anything left of the region. If there is, at least one part of the window wasn't overlapped.



来源:https://stackoverflow.com/questions/5445889/get-which-process-window-is-actually-visible-in-c-sharp

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