RegisterHotKey の処理で GetFocus をしたい場面が出てくるとします。
#include <windows.h>
#include <stdio.h>
int main() {
while (1) {
HWND hwndForeground = GetForegroundWindow();
DWORD procId = 0;
DWORD threadId = GetWindowThreadProcessId(hwndForeground, &procId);
AttachThreadInput(GetCurrentThreadId(), threadId, true);
HWND hwndActive = GetActiveWindow();
HWND hwndFocus = GetFocus();
AttachThreadInput(GetCurrentThreadId(), threadId, false);
printf("%p %p %p \n", hwndForeground, hwndActive, hwndFocus);
Sleep(100);
}
}
このようにしたらいけました。AttachThreadInput がキモですね…
GetActiveWindow == GetForegroundWindow になります。
GetFocus で、目当てのコントロールが取得できます。
0 件のコメント:
コメントを投稿