如何解决我正在尝试使用 Winapi 检查指定的窗口是否在屏幕上可见,但不确定在两个窗口不重叠时如何处理
我想要做的是组合顶部窗口的区域并检查指定的窗口是否存在于该区域中,如果它正在显示结果。它没有非常准确地给出结果。当窗口不重叠时,我也有问题。有没有人知道如何克服这种情况。
p
是前台进程
while (p != NULL)
{
if (IsWindowVisible(p)) {
if ((GetWindowLongPtr(p,GWL_STYLE) & WS_ICONIC) || GetWindowLong(p,GWL_EXSTYLE) & WS_EX_TOOLWINDOW) {
}
else
{
RECT a;
if (GetWindowText(p,str,255)) {
if ((_wcsicmp(str,_T("Program Manager"))))
{
GetWindowThreadProcessId(p,&proc_id);
proc_hnd = OpenProcess(PROCESS_ALL_ACCESS,TRUE,proc_id);
flag = GetProcessImageFileName(proc_hnd,proc_name,1024);
wstring test(&proc_name[0]); //convert to wstring
string test2(test.begin(),test.end());
LOGGER->info(test2);
GetWindowRect(p,&a);
z = CreateRectRgn(a.left,a.top,a.right,a.bottom);
if (wcsstr(proc_name,L"chrome.exe")) {
RECT op;
GetWindowRect(p,&op);
HRGN j1 = CreateRectRgn(op.left,op.top,op.right,op.bottom);
CombineRgn(j1,j1,y,RGN_DIFF); emphasized text
CombineRgn(y,z,RGN_OR); //combining the region
switch (GetRgnBox(j1,&a))
{
case NULLREGION:
LOGGER->info("null region");
break;
case SIMPLEREGION:
LOGGER->info("simple region");
break;
case COMPLEXREGION:
LOGGER->info("complex region");
break;
default:
LOGGER->info("default region");
}
}
else
{
CombineRgn(y,RGN_OR); //combining the region
}
}
}
}
}
p = GetWindow(p,GW_HWNDNEXT); //getting the next window
}
解决方法
我这里使用了IsOverlapped
sample,但是它是用来检测是否有任何窗口重叠的。我修改了这个示例来检查窗口是否可见:
BOOL IsVisible(HWND window)
{
HWND hWnd = window;
RECT thisRect;
if (!IsWindowVisible(window))
return FALSE;
GetWindowRect(window,&thisRect);
HWND explorer = FindWindow(L"Shell_TrayWnd",NULL);
DWORD explorer_pid;
GetWindowThreadProcessId(explorer,&explorer_pid);
HRGN hrgn_above = CreateRectRgn(0,0);
HRGN hrgn_window = CreateRectRgnIndirect(&thisRect);
while ((hWnd = GetWindow(hWnd,GW_HWNDPREV)) != NULL)
{
DWORD pid;
GetWindowThreadProcessId(hWnd,&pid);
if (pid == explorer_pid || !IsWindowVisible(hWnd))
continue;
RECT rc = {};
GetWindowRect(hWnd,&rc);
HRGN hrgn_hWnd = CreateRectRgn(rc.left,rc.top,rc.right,rc.bottom);
CombineRgn(hrgn_above,hrgn_above,hrgn_hWnd,RGN_OR);
DeleteObject(hrgn_hWnd);
}
int ret = CombineRgn(hrgn_window,hrgn_window,RGN_DIFF);
DeleteObject(hrgn_above);
DeleteObject(hrgn_window);
if (ret != NULLREGION && ret)
return TRUE;
return FALSE;
}
使用 GetWindow
+ GW_HWNDPREV
以 Z 顺序获取 hWnd
上方的窗口列表。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。