程序的出站系统消息有没有办法"listen"?

Is there a way to "listen" for a program's outbound system messages?

我正在尝试复制一个自动化工具的行为,该工具将一些系统消息发送到具有指定 window 句柄的程序,但我不确定它使用的是哪些消息。有没有办法收听程序的出站系统消息?这是 Windows.

我的副本是在 C# 中,但我也熟悉 C++,并且可以使用第 3 方工具(如果可用)(或者如果有一个小众的 Win32 API 函数可以做这样的事情,我可以欺骗一个副项目一起)。

谢谢!

I'm trying to replicate the behaviour of an automation tool that sends a few system messages to a program with the specified window handle but I'm not sure which messages it's using. Is there a way to listen to a program's outbound system messages?

如果自动化工具正在使用 window 消息,您可以使用 Spy++、Winsight 等监控工具实时查看它们。

或者,您可以简单地使用 SetWindowsHookEx()WH_GETMESSAGE/WH_CALLWNDPROC(RET) 挂钩在您自己的代码中挂钩目标 window 的消息。您可以使用 GetWindowThreadProcessId() 获取 window 的拥有线程 ID,以便您仅挂钩该线程而不是系统中的其他线程。