Esempio n. 1
0
        private void HandleHook(IntPtr hook, SetWinEventHookEventType eventType,
                                IntPtr window, int objectId, int childId, uint threadId, uint time)
        {
            if (_disposed == false)
            {
                lock (_stateLock)
                {
                    if (_started)
                    {
                        var eventArgs = new GrabbedEventArgs
                        {
                            EventType = eventType,
                            Window    = window,
                            ObjectId  = objectId,
                            ChildId   = childId,
                            ThreadId  = threadId,
                            Time      = time
                        };

                        if (Grabbed != null)
                        {
                            Grabbed(this, eventArgs);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private static void WinEventProc(IntPtr hook, SetWinEventHookEventType eventType, IntPtr window, int objectId, int childId, uint threadId, uint time)
        {
            try
            {
                if (eventType == SetWinEventHookEventType.EVENT_SYSTEM_FOREGROUND ||
                    eventType == SetWinEventHookEventType.EVENT_SYSTEM_MOVESIZEEND)
                {//焦点变化,窗口大小变化
                    var m = new OtherProgramChecker(_currentProcess).CheckMaximized();
                    RaiseMaximizedEvent(m);
                }

                if (eventType == SetWinEventHookEventType.EVENT_OBJECT_LOCATIONCHANGE)
                {//处理最大化操作
                    WINDOWPLACEMENT placment = new WINDOWPLACEMENT();
                    User32Wrapper.GetWindowPlacement(window, ref placment);
                    //string title = User32Wrapper.GetWindowText(window);
                    int pid = User32Wrapper.GetProcessId(window);
                    if (placment.showCmd == WINDOWPLACEMENTFlags.SW_HIDE)
                    {
                        return;
                    }

                    if (pid == _currentProcess.Id)
                    {
                        return;
                    }

                    if (placment.showCmd == WINDOWPLACEMENTFlags.SW_SHOWMAXIMIZED)
                    {
                        if (!maximizedPid.Contains(pid))
                        {
                            maximizedPid.Add(pid);
                            var m = new OtherProgramChecker(_currentProcess).CheckMaximized();
                            RaiseMaximizedEvent(m);
                        }
                    }

                    if (placment.showCmd == WINDOWPLACEMENTFlags.SW_SHOWNORMAL ||
                        placment.showCmd == WINDOWPLACEMENTFlags.SW_RESTORE ||
                        placment.showCmd == WINDOWPLACEMENTFlags.SW_SHOW ||
                        placment.showCmd == WINDOWPLACEMENTFlags.SW_SHOWMINIMIZED)
                    {
                        if (maximizedPid.Contains(pid))
                        {
                            maximizedPid.Remove(pid);
                            var m = new OtherProgramChecker(_currentProcess).CheckMaximized();
                            RaiseMaximizedEvent(m);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Esempio n. 3
0
 public static extern IntPtr SetWinEventHook(SetWinEventHookEventType eventTypeMin,
                                             SetWinEventHookEventType eventTypeMax, IntPtr library, SetWinEventHookDelegate handler,
                                             uint processId, uint threadId, SetWinEventHookFlag flags);
Esempio n. 4
0
        private void HandleHook(IntPtr hook, SetWinEventHookEventType eventType, 
            IntPtr window, int objectId, int childId, uint threadId, uint time)
        {
            if (disposed == false)
            {
                lock (stateLock)
                {
                    if (started)
                    {
                        var eventArgs = new GrabbedEventArgs
                        {
                            EventType = eventType,
                            Window = window,
                            ObjectId = objectId,
                            ChildId = childId,
                            ThreadId = threadId,
                            Time = time
                        };

                        if (Grabbed != null)
                        {
                            Grabbed(this, eventArgs);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
 public static extern IntPtr SetWinEventHook(SetWinEventHookEventType eventTypeMin,
     SetWinEventHookEventType eventTypeMax, IntPtr library, SetWinEventHookDelegate handler,
     uint processId, uint threadId, SetWinEventHookFlag flags);