Я получил ответ после попытки более 2 часов с Google. Вот что у меня есть:
StringBuilder builder = new StringBuilder(500);
int foregroundWindowHandle = GetForegroundWindow();
uint remoteThreadId = GetWindowThreadProcessId(foregroundWindowHandle, 0);
uint currentThreadId = GetCurrentThreadId();
//AttachTrheadInput is needed so we can get the handle of a focused window in another app
AttachThreadInput(remoteThreadId, currentThreadId, true);
//Get the handle of a focused window
int focused = GetFocus();
//Now detach since we got the focused handle
AttachThreadInput(remoteThreadId, currentThreadId, false);
Поскольку у нас есть дескриптор окна фокуса, мы можем получить его имя / класс и другую необходимую информацию
В этом случае я просто узнаю имя класса:
StringBuilder winClassName = new StringBuilder();
int numChars = CustomViewAPI.Win32.GetClassName((IntPtr)focused, winClassName,
winClassName.Capacity);