Window Name Modified Event

If a window, for example. Firefox will change the name, from Firefox to Qaru - Firefox , then I want my application to write that Firefox changed the name.

Is this possible without using a hook and loop (EnumWindows)? If this can only be done with a hook, what type of hook?

+6
source share
3 answers

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.

+9
source

You will need a hook (or the polling method that you mentioned in your question).

Mostly in the Windows API, in order to change the "window title" - or rather, the window text - you send WM_SETTEXT , so your hook should intercept this message. You need the hook type WH_CALLWNDPROC and just check if the message you receive is WM_SETTEXT , and hWnd is the main window for the application you are looking for (so you do not get false positives such as the application tries to set the text of the child windows).

A small note here. Although this is probably not the case, remember that the title you see can simply be drawn there manually, and not through the regular Windows API. Use Spy ++ or something to see what happens, before you go too far along this route, you can spend a lot of time on nothing.

+3
source

You do not need any hooks. Just use windows events

-7
source

Source: https://habr.com/ru/post/905354/


All Articles