Tracking window title change

c++ / delphi package - dll injection and api hooking
Post Reply
SittingBull
Posts: 23
Joined: Fri Jun 03, 2005 2:17 pm

Tracking window title change

Post by SittingBull »

I'd like to track all window title changes that occur within a given session, I've managed to successfully do this hook SendMessageA/W and PostMessageA/W.

Is there any function one could intercept, or an event to subscribe, in order to get notified off all window title changes?

Thanks in advance,
SittingBull
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

You could use SetWindowsHookEx, I guess, and catch WM_SETTEXT messages.
SittingBull
Posts: 23
Joined: Fri Jun 03, 2005 2:17 pm

Post by SittingBull »

madshi wrote:You could use SetWindowsHookEx, I guess, and catch WM_SETTEXT messages.
I'm using madchook's injection lib for system wide hooking, so SetWindowsHookEx had to be used localy for each process. Can this be done? Using SetWindowsHookEx on the local process?

Or is there any other way of intercepting it? Perhaps something in a lower level... :P
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Well, you could stop using madCodeHook and use SetWindowsHookEx instead. You could also do one SetWindowsHookEx call for each process, but that doesn't sound very good for performance.
SittingBull
Posts: 23
Joined: Fri Jun 03, 2005 2:17 pm

Post by SittingBull »

madshi wrote:Well, you could stop using madCodeHook and use SetWindowsHookEx instead.
Given the architecture of the application I'm creating this cant be done (I need to hook system processes, and my main process has to run on the system account).
madshi wrote:You could also do one SetWindowsHookEx call for each process, but that doesn't sound very good for performance.
It might be better for performance than hooking sendmessage and postmessage, I belive! Maybe i'll try this.

Mean while I've been wondering if one could hook the windowproc to monitor WM_SETTEXT. What do you think about this?

Thanks for your replys :)
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

SittingBull wrote:It might be better for performance than hooking sendmessage and postmessage, I belive!
Why? Are you having performance problems with SendMessage + PostMessage hooking?
SittingBull wrote:Mean while I've been wondering if one could hook the windowproc to monitor WM_SETTEXT. What do you think about this?
You can do that by subclassing each window by calling SetWindowLong(GWL_WNDPROC). But I don't recommend that. Subclassing every window sounds like overkill to me!!
SittingBull
Posts: 23
Joined: Fri Jun 03, 2005 2:17 pm

Post by SittingBull »

madshi wrote:Why? Are you having performance problems with SendMessage + PostMessage hooking?
It affects a bit the performance (CPU appears with current usage about 2-5% never touching 0%, by desactivating this hook cpu usage touches 0 sometimes), since every message in the system is scanned only to find the WM_SETTEXT :confused:.

But the main problem is that hooking this functions hangs up an application I have (a scanner related application, for digitalization process management), when I'm not hooking the sendmessage and postmessage it works fine! I belive it has something to do with the apperance of a message box in the window, perhaps because I'm comunicating with the applications main process inside the hook.
madshi wrote:You can do that by subclassing each window by calling SetWindowLong(GWL_WNDPROC). But I don't recommend that. Subclassing every window sounds like overkill to me!!
Hum, you're right, it might even be worst than what I have.
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

How does your PostMessage/SendMessage hook code look like? The hook itself should not noticably impact performance. Probably it's what you're doing inside the hook callback function, which is the problem.
SittingBull
Posts: 23
Joined: Fri Jun 03, 2005 2:17 pm

Post by SittingBull »

madshi wrote:How does your PostMessage/SendMessage hook code look like? The hook itself should not noticably impact performance. Probably it's what you're doing inside the hook callback function, which is the problem.
Yes thats the problem, I've to comunicate with the main process, the only overhead is that the hook has to find out if a window is a toplevel application window (only comunicates WM_SETTEXT for those windows).

An aditional overhead comes when one window is determined to be top level, and the title has to be comunicated to my applications main process.

How could one fastly determine if a window is top level?
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Probably "GetParent(window) = 0", I guess? So you need to work on that code. Regardless of which hooking method you're using, if your code is not fast enough, it doesn't help switching to another hooking method.
SittingBull
Posts: 23
Joined: Fri Jun 03, 2005 2:17 pm

Post by SittingBull »

Well thanks for the reply, this is what I'm doing, and am getting better results on CPU usage... :D

Best Regards,
Sitting Bull
Post Reply