0

I would like to capture selected messages from another application similar to the way Spy++ 64 does. I don't have a clue where to start. I guess I need something like WndProc only it would fire for external application not my application.

I looked at the code in the post Capture all Windows Messages and am not sure it will actually do what I want and I would like a VB.Net Solution.

What I am trying to do is to hook the WM_PAINT message from another application. Take Notepad as a simple example. In Spy++ 64 I would click Spy->Log Messages, target the textbox body area of Notepad, Click the General checkbox on the Messages Tab and every time Notepad is repainted Spy++ 64 shows: 00140A1C P WM_PAINT

Does anyone have any ideas or can you point me in the right direction?

Jim Dandy BOA
  • 533
  • 7
  • 13
  • Is there a specific rason why you want to receive `WM_Paint` notifications? Because the text has changed?. You have some other options. [SetWinEventHook](https://learn.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setwineventhook), safer than `SetWindowsHookEx` (see an example here to hook a Window movement: [Move window when external application's window moves](https://stackoverflow.com/a/48812831/7444103)) . You also have [UI Automation](https://learn.microsoft.com/en-us/windows/desktop/winauto/entry-uiauto-win32), which generates almost the same notifications. – Jimi Apr 11 '19 at 05:42
  • UI Automation should be the preferred way, if you want to receive notifications when a Window (or a child Window/Control) in the system changes some of its properties. It's also easier to use (its logic might appear somewhat awkward if you've never used it before, though). It all depends on what you actually want to know about a *foreign* Window and its child controls. – Jimi Apr 11 '19 at 05:50
  • Thank you Jimi, I'll check it out and see if it handles events and if I can find any examples in Visual Basic .Net. The reason I want to know is to detect if an application's window is actually visible after launching it in a New Process. The API call IsWindowVisible always returns true a few seconds before the window is actually visible on the desktop. I just thought maybe if I could detect the WM_PAINT message it might be a little more accurate. – Jim Dandy BOA Apr 12 '19 at 02:55
  • Using the Process class to start a windowed process, you can wait for the main window to become active with `[Process].WaitForInputIdle()`. You can do the same thing using UI Automation: you can start the process (or just detect when the Application main process is started by a 3rd party entity) and receive a notification when the main Window is created, using the [WindowPattern.WindowOpenedEvent](https://learn.microsoft.com/en-us/dotnet/api/system.windows.automation.windowpattern.windowopenedevent). – Jimi Apr 12 '19 at 05:48
  • Here's a VB.Net implementation: [Add an event to all Forms in a Project](https://stackoverflow.com/a/51505218/7444103). This procedure detects a Window Opened event in the current process (your own app), because it filters the current process `ProcessId`. This event is however related to any Window in the System. If you need an example for a specific use, let me know. – Jimi Apr 12 '19 at 05:49

0 Answers0