WinEvents is the way here. Required API SetWinEventHook () - if you care about a particular window, use GetWindowThreadProcessId () to get the HWND threadId and then listen for events only from that specific thread. To change the window name, you need the EVENT_OBJECT_NAMECHANGE event.
You can connect either “in context” or “out of context” - the latter is the simplest and means that the event is delivered back to your own process, so you do not need a separate DLL, which makes it possible to do all this in C #; but the thread that calls SetWinEventHook must have a message loop (GetMessage / TranslateMessage / DispatchMessage), because events are delivered using the message form behind the scenes.
In your WinEvent callback, you will need to verify that HWND is the one you care about, as you will get name changes for any user interface in this target stream, possibly including child window name changes or other things you don't care about .
-
By the way, you can check this answer for sample C # code that uses WinEvents; he uses them to track foreground window changes in all windows on the desktop; but you just need to make a few simple changes as described above to track name changes in a specific window.
source share