获取 C# 中实际可见的进程/窗口
我有所有打开的窗口的列表,即窗口任务栏中的窗口。我想要做的是删除列表中不可见的内容。
我的意思是,如果一个窗口被另一个窗口隐藏,它不应该出现在我的列表中。
过去两天我一直在谷歌搜索但没有成功......
有什么想法吗?
PS:我可以获取每个进程的位置和大小,因此获取进程的上次使用时间/空闲时间也可以...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用区域,窗口中仍然可见的内容可以是一组复杂的矩形。从要检查的窗口开始,GetWindowRect 和 CreateRectRegion 为窗口矩形创建一个区域。
循环调用 GetWindow(),传递 GW_HWNDPREV。它返回 Z 顺序中的前一个窗口,以便它可以重叠。 GetWindowRect() 获取其矩形,CreateRectRegion() 并使用带有RGN_DIFF 的CombineRgn() 将其与原始窗口区域组合。
当 GetWindow 返回 NULL 时,您已找到所有可能重叠的窗口。使用 GetRgnBox 检查该区域是否还有剩余内容。如果存在,则至少窗口的一部分没有重叠。
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.