【发布时间】:2013-11-14 00:38:04
【问题描述】:
我想检测所有顶级窗口,以便向它的后代发送消息。 我怎样才能做到这一点? 下面的代码好像没有检测到Qt顶层窗口,不知道为什么。
static BOOL CALLBACK EnumWindowsProc(_In_ HWND hwnd, _In_ LPARAM lParam) {
WORD far wndProcessID;
WORD currentProcessID = GetCurrentProcessId();
std::vector<HWND> *topWindowList = (std::vector<HWND> *)lParam;
if (topWindowList != NULL &&
GetWindowThreadProcessId(hwnd, NULL) == currentProcessID) {
printf("Found a top level window");
fflush(stdout);
topWindowList->push_back(hwnd);
}
return TRUE;
}
void enumAllDesktopChildWindow() {
std::vector<HWND> topWindowList;
EnumChildWindows(GetDesktopWindow(), EnumWindowsProc, LPARAM(&topWindowList));
}
【问题讨论】:
-
你试过只用
EnumWindows吗? -
在 Qt 应用程序中,您可以使用可移植的
QGuiApplication::topLevelWindows()