c++ - 有什么办法可以找出哪个线程收到了最后的输入?

标签 c++ c winapi input

我目前正在诊断窗口激活问题,其中调用 SetForegroundWindow失败了,即使我相信它是从前台线程调用的。当输入来自触摸数字化仪时,该问题会重现。

有什么方法可以找出哪个线程收到了最后的输入?我试着调用 GetWindowThreadProcessId在从 GetForegroundWindow 返回的句柄上.但是,这似乎返回了过时的信息,就在窗口输入激活之后1)

由于这仅用于诊断问题,如果公共(public)接口(interface)不可用,我很乐意使用未记录接口(interface)的解决方案。如果这很重要,目标平台是 Windows 7 64 位。


1) GetForegroundWindow 返回相同的句柄,无论输入来自触摸数字化仪还是指点设备。当输入来自定点设备时,对 SetForegroundWindow 的后续调用成功,但触摸输入失败。

最佳答案

Since this is only for diagnosing an issue, I'm happy with a solution using undocumented interfaces, if public interfaces aren't available.

您可以尝试使用 SetWindowsHookEx 为 WH_GETMESSAGE 安装系统范围的 Hook ,并监视 WM_SETFOREGROUND 等有趣的消息。 IE。在调用原始版本之前记录有趣的东西。

另一个想法是使用 MHOOK Hook SetForegroundWindow API或 Detours .正如你在这里看到的https://superuser.com/questions/18383/preventing-applications-from-stealing-focus ,使用 mhook 看起来非常简单。

关于c++ - 有什么办法可以找出哪个线程收到了最后的输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32190363/

相关文章:

c - 删除一个字符的字符串匹配

c++ - 如何检查鼠标在最后 5 秒内没有移动?

c++ - 类型转换自定义 C++ 类

c++ - 使用 windows.h 时 undefined reference

c++ - 帮助内存泄漏 (malloc)

c - Linux C,如何安排10个等待线程以FIFO方式执行?

c++ - (F)莱克斯 : get text not matched by rules/get default output

c++ - 如何在没有无限循环的情况下使用 CMake 的 add_subdirectory

c++ - 是否可以保护内存区域免受 WinAPI 的影响?

winapi - Win32 API 提供的数据结构?