Monday, 15 July 2013

c# - Fire event when user changes active process -


Is there an event, or a way to create an event, that the program changes user active window is a different process ?

If there is no such incident, then what is the best way to do something like this?

I currently have a timer that runs the process. GetCurrentProcess () every 3 seconds, but I'm searching for a better and more efficient way of doing it and it takes too much time because I do not want to reduce the risk interval because of the program taking too much resources or making that To continuously check the active process.

I know that a lot of Windows has been created in the functions which are basically hidden that I do not have enough knowledge to know about it, so if someone has some ideas like this, If you can help me then it would be great.

The API is exactly what you are looking for here all you need to do is The phone is when your app starts with the right option and you should start receiving attention from the user changes any process that is currently running on the desktop whenever you want to receive notifications. [DllImport ("user32.dll", SetLastError = true)] Internal Fixed Execution IntPtr SetWinEventHook (uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventProc lpfnWinEventProc, integer idProcess, integer idThread, uint dwflags ); [DllImport ("user32.dll")] Internal Stable Extern int UnhookWinEvent (IntPtr hWinEventHook); Internal Representative Zero WinEventProc (IntPtr hWinEventHook, uint iEvent, IntPtr hWnd, integer idObject, integer idChild, integer dwEventThread, integer dwmsEventTime); CONST UIT WINEVENT_OUTOFCONTEXT = 0; CONSTANT EVENT_SYSTEM_FOREGROUND = 3; Private Intercept Win Hook; Private WinEventProc listener; Public Zero StartArticlesForward Change () {listenener = new WinEventProc (event callback); // set window hook winHook = SetWinEventHook (EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, listener, 0, 0, WINEVENT_OUTOFCONTEXT); } Public Zero Stoplighting Forvideo Change () {UnhookWinEvent (winHook); } Private Static Zero EventCallback (IntPtr hWinEventHook, uint iEvent, IntPtr hWnd, integer idObject, integer idChild, integer dwEventThread, integer dwmsEventTime) {// Enable active window change! }

No comments:

Post a Comment