Ivan G.
Ivan G.

Reputation: 5215

System-wide focus

Is it possible to get HWND of currently focused window? For the whole windows station, not the current application. Target application is Win32. I can get current window using :GetForegroundWindow() however, this is the main window only. I can enumerate child windows, but how do I determine if it's focused?

Upvotes: 1

Views: 184

Answers (1)

Ray
Ray

Reputation: 1585

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;
}

Upvotes: 2

Related Questions