是否可以获得当前焦点窗口的HWND?对于整个Windows工作站,不是当前的应用程序。目标应用程序是Win32。我可以使用以下命令获取当前窗口:GetForegroundWindow()但是,这只是主窗口。我可以枚举子窗口,但我如何确定它是否聚焦?
答案 0 :(得分:2)
HWND RemoteGetFocus()
{
HWND hwnd = GetForegroundWindow();
DWORD remoteThreadId = GetWindowThreadProcessId(hwnd, NULL);
DWORD currentThreadId = GetCurrentThreadId();
AttachThreadInput(remoteThreadId, currentThreadId, TRUE);
HWND focused = GetFocus();
AttachThreadInput(remoteThreadId, currentThreadId, FALSE);
return focused;
}