1
votes

I want to be able to detect using events, when a Window (not necessarily the application I'm creating) changes its title.

My ideas (but none of them uses a specialized event):

  • Add an event to the mouse click and keyboard strokes, that way I can detect when the title will change, but it's not perfect, since the title may change a few seconds after the last click (e.g. loading a website)
  • Do some polling only on whitelisted applications

EDIT: I managed to put the EVENT_SYSTEM_CAPTURESTART hook, which captures clicks. It does work for changing tabs, but for loading new pages, it will not capture the change because pages usually take some time to load.

1
@andlabs I was able to detect when the user focused on a different window (detect window changes), but in Chrome there's one window with many tabs, so for software like this I want to detect the window title changes. Basically I want to detect the different software the user uses, and when does s/he changes windows. Like a monitor.Chris Vilches
AFAIK, there is no event for window title changes. You might need to use SetWindowsHookEx to intercept WM_SETTEXT messages. But some apps have custom-drawn titles, so this is not a universal solution.Remy Lebeau
Wait, you want to inspect what tabs the user opens in their web browser? You'll have to talk to the web browser directly for that; Windows provides no universal browser communications API. (And what happened to my original comment?)andlabs

1 Answers

1
votes

I'm doing this by using UIA (as suggested by Hans). I detect when a new window opens, get the UIA element, and subscribe to the property changed event handler for it for the NameProperty.

Automation.AddAutomationPropertyChangedEventHandler(
    <your window AutomationElement>, 
    TreeScope.Element, 
    <your delegate>, 
    AutomationElement.NameProperty);