/// <summary> /// Handle the WinEvent /// </summary> /// <param name="hWinEventHook">The Hook IntPtr</param> /// <param name="eventType">Event Type to handle, enum WinEvent</param> /// <param name="hwnd">Window handle which caused the event</param> /// <param name="idObject">Object ID, enum EventObjects</param> /// <param name="idChild">Child ID of the window</param> /// <param name="dwEventThread">Thread which generated the ID</param> /// <param name="dwmsEventTime"></param> private static void WinEventProc(IntPtr hWinEventHook, WinEvent eventType, IntPtr hwnd, EventObjects idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { // Check if it's an event generated by a Window if (hwnd == IntPtr.Zero || idObject != EventObjects.OBJID_WINDOW) { // Other events do not interest us. return; } String classname = null; // Check if the event was generated by the OLE Event Thread, which causes a lot of create/destroy if (oleEventThread != 0 && dwEventThread == oleEventThread) { return; } // Only get the classname when it's not a destroy (classname is not available) if (eventType == WinEvent.EVENT_OBJECT_CREATE) { classname = WindowDetails.GetClassName(hwnd); // Make sure the OleMainThreadWndClass events are ignored. if (oleEventThread == 0) { if (classname == "OleMainThreadWndClass") { oleEventThread = dwEventThread; return; } } } LOG.DebugFormat("eventType={0},hwnd={1},classname={4},idObject={2},idChild={3},dwEventThread={5}", eventType, hwnd, idObject, idChild, classname, dwEventThread); }