public void Start()
 {
     Stop();
     checkWindowsThread = new Thread(() =>
     {
         while (true)
         {
             // Check windows list
             int windowCount = 0;
             WindowInterop.EnumWindows((h, p) =>
             {
                 if (isTaskBarWindow(h))
                 {
                     windowCount++;
                 }
                 return(true);
             }, 0);
             if (windowCount != Windows.Count && WindowListChanged != null)
             {
                 WindowListChanged(this, new EventArgs());
             }
             // Check active window
             IntPtr activeWindow = WindowInterop.GetForegroundWindow();
             if (ActiveWindow != activeWindow && ActiveWindowChanged != null && activeWindow != dockHwnd)
             {
                 ActiveWindowChanged(activeWindow, new EventArgs());
             }
             // Check active window location
             if (activeWindow != IntPtr.Zero && activeWindow != dockHwnd)
             {
                 WindowInterop.Rect windowRect = new WindowInterop.Rect();
                 WindowInterop.GetWindowRect(activeWindow, ref windowRect);
                 if (windowRect != ActiveWindowRect && ActiveWindowRectChanged != null)
                 {
                     ActiveWindowRectChanged(this, new WindowRectEventArgs(ActiveWindowRect = windowRect));
                 }
             }
             // Check current cursor position
             WindowInterop.Point cPos;
             WindowInterop.GetCursorPos(out cPos);
             if (CursorPosition != cPos && CursorPositionChanged != null)
             {
                 CursorPositionChanged(this, new CursorPosEventArgs(CursorPosition = cPos));
             }
             Thread.Sleep(40); // ~25ips
         }
     });
     checkWindowsThread.Start();
 }
Exemple #2
0
 public void Start()
 {
     Stop();
     checkWorkingAreaThread = new Thread(() =>
     {
         SystemInterop.RECT rect = WorkAreaManager.GetWorkingArea();
         while (true)
         {
             var newRect = WorkAreaManager.GetWorkingArea();
             if (rect.Bottom != newRect.Bottom ||
                 rect.Top != newRect.Top ||
                 rect.Left != newRect.Left ||
                 rect.Right != newRect.Right)
             {
                 if (WorkingAreaChanged != null)
                 {
                     WorkingAreaChanged(this, new EventArgs());
                 }
                 rect = newRect;
             }
             Thread.Sleep(100); // ~10ips
         }
     });
     checkWorkingAreaThread.Start();
     checkWindowsThread = new Thread(() =>
     {
         while (true)
         {
             // Check windows list
             int windowCount = 0;
             WindowInterop.EnumWindows((h, p) =>
             {
                 if (isTaskBarWindow(h))
                 {
                     windowCount++;
                 }
                 return(true);
             }, 0);
             if (windowCount != Windows.Count && WindowListChanged != null)
             {
                 WindowListChanged(this, new EventArgs());
             }
             // Check active window
             IntPtr activeHwnd = WindowInterop.GetForegroundWindow();
             var activeWindow  = new Win32Window(activeHwnd);
             var isDock        = activeWindow.FileName == Process.GetCurrentProcess().MainModule.FileName;
             if (ActiveWindow != activeHwnd && ActiveWindowChanged != null && !isDock)
             {
                 ActiveWindowChanged(activeHwnd, new EventArgs());
             }
             // Check active window location
             if (activeHwnd != IntPtr.Zero && !isDock)
             {
                 WindowInterop.Rect windowRect = new WindowInterop.Rect();
                 WindowInterop.GetWindowRect(activeHwnd, ref windowRect);
                 if (windowRect != ActiveWindowRect && ActiveWindowRectChanged != null)
                 {
                     ActiveWindowRectChanged(this, new WindowRectEventArgs(ActiveWindowRect = windowRect));
                 }
             }
             Thread.Sleep(50); // ~20ips
         }
     });
     checkWindowsThread.Start();
 }