automation - Can I use window hooks in C# to determine if a window gains or loses focus? -
i've written c# application automates instance of ie. i'd know when internet explorer gains focus , when looses focus.
from shdocvw.internetexplorer object can it's hwnd. there how can create message hook receive wm_killfocus , wm_focus events (assuming correct events listening :))?
thanks everyone!!
update: found way use accomplish above goal without using hooks (which haven't quite figured out how in c# yet), using .net framework in question.
the problem code
automationfocuschangedeventhandler focushandler = new automationfocuschangedeventhandler(onfocuschanged); automation.addautomationfocuschangedeventhandler(focushandler);
is easy window foreground window , event won't fire when window switched because it's waiting specific ui element in focus. (to test can use function uses code , prints message everytime new window in focus, such msdn sample trackfocus, , click on webbrowser. when webpages or blank page being displayed in browser event wont fire until address bar or other element selected.) work if there way modify throw event if either no ui element in focus or every time element lost focus (instead being thrown when gains focused). have ideas on how fix above code solve problem?
update 2: came across (article claims can hook mouse , keyboard c#) may mean can't use hooks @ i'd do.
detailed instructions on setting hook c# here: http://support.microsoft.com/kb/318804/en-us?fr=1
Comments
Post a Comment