Search code examples
c#c++winapiwindows-messages

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


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? This is for Windows.

My replica is in C# but I'm familiar with C++ as well, and can use 3rd party tools if available (or if there is a niche Win32 API function that does something like this I can finagle a side project together).

Thank you!


Solution

  • 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?

    If the automation tool is using window messages, you can use monitoring tools like Spy++, Winsight, etc to view them in real time.

    Or, you can simply hook the messages of the target window yourself in your own code using the WH_GETMESSAGE/WH_CALLWNDPROC(RET) hooks of SetWindowsHookEx(). You can use GetWindowThreadProcessId() to get the owning thread ID of the window, so that you are hooking only that thread and not other threads in the system.