I am trying to capture the change event of the active Window. Let's say if a user is working on VS and he is switching to IE, I want to capture this event with an active window. I searched the Internet and found many examples, but nothing works for me.
This is the code that I have written so far, I'm not sure if this is not the case. I can not capture the necessary event through this
class Program { delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime); [DllImport("user32.dll")] static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags); private const uint WINEVENT_OUTOFCONTEXT = 0; private const uint EVENT_SYSTEM_FOREGROUND = 3; static void Main(string[] args) { WinEventDelegate dele = new WinEventDelegate(WinEventProc); IntPtr m_hhook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, dele, 0, 0, WINEVENT_OUTOFCONTEXT); Console.ReadKey(); } static void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { Console.WriteLine("Something"); } }
WinEventProc will never be called, can anyone determine what I am doing wrong programmatically or conceptually? I am using windows 7
source share