gpt4 book ai didi

c++ - 使用 FindWindow() 时如何跳过隐藏的窗口?

转载 作者:行者123 更新时间:2023-11-30 00:59:29 31 4
gpt4 key购买 nike

我创建了一个没有显示的窗口:

int main()
{
CreateWindow("SysListView32","Geek",0, 0, 0, 0, 0,NULL, NULL, (HINSTANCE)GetCurrentProcess(), NULL);

getch();
}

...并在另一个进程中使用 FindWindow()找到它的句柄:

int main()
{
HWND H = FindWindow("SysListView32", "Geek");
std::cout<< "The handle of created window is : " <<H;

getch();
}

FindWindow 如何找到它的句柄?我假设它不会找到它,因为 process1 没有显示窗口。

我怎样才能只找到可见窗口?

最佳答案

即使一个窗口不可见,它当然在 FindWindow 枚举的所有现有窗口的列表中(例如,您可以使用 Spy++ 显示此列表)。如果您不想搜索隐藏的窗口,则必须检查它们的标志:

HWND H = FindWindow("SysListView32", "Geek");
if (H) {
LONG style = GetWindowLong(H, GWL_STYLE);
if (style & WS_VISIBLE)
std::cout << "The handle of created visible window is : " << H << std::endl;
else
std::cout << "The handle of created hidden window is : " << H << std::endl;
} else {
std::cout << "No such window found" << std::endl;
}

关于c++ - 使用 FindWindow() 时如何跳过隐藏的窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4247897/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com