tags:

views:

44

answers:

1
+1  Q: 

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?

+2  A: 
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;
}
Ray
Brilliant! Thanks!
aloneguid