Get which process/window is actually visible in C#
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 an开发者_如何学编程d size of each process, so getting the last time a process was used/idle time would work too...
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.
精彩评论