Ejemplo n.º 1
0
 public WindowEventArgs(Win32Window window)
 {
     Window = window;
 }
Ejemplo n.º 2
0
 private bool isTaskBarWindow(IntPtr hwnd)
 {
     //long style = WindowInterop.GetWindowLongPtr(hwnd, WindowInterop.GWL_STYLE); // Get style.
     if (/*HasFlag(style, TARGETWINDOW) &&*/
         WindowInterop.IsWindowVisible(hwnd) /*&&
         WindowInterop.GetParent(hwnd) == IntPtr.Zero*/)
     {
         var window = new Win32Window(hwnd);
         bool noOwner = WindowInterop.GetWindow(hwnd, WindowInterop.GW_OWNER) == IntPtr.Zero;
         long exStyle = WindowInterop.GetWindowLongPtr(hwnd, WindowInterop.GWL_EXSTYLE); // Get extended style.
         bool isWin10App = window.ClassName == "ApplicationFrameWindow";
         return noOwner && (exStyle & WS_EX_TOOLWINDOW) == 0 && !isWin10App;
     }
     return false;
 }
Ejemplo n.º 3
0
 void WindowManager_WindowListChanged(object sender, EventArgs e)
 {
     List<IntPtr> hwnds = new List<IntPtr>();
     WindowInterop.EnumWindows((h, p) =>
     {
         if(isTaskBarWindow(h))
             hwnds.Add(h);
         return true;
     }, 0);
     List<IntPtr> chwnds = (from w in Windows select w.Hwnd).ToList();
     foreach (var h in hwnds.Except(chwnds)) // Get removed windows
     {
         var window = new Win32Window(h);
         Windows.Add(window);
         if (WindowAdded != null)
             WindowAdded(this, new WindowEventArgs(window));
     }
     foreach (var h in chwnds.Except(hwnds)) // Get added windows
     {
         var window = Windows.Find(w => w.Hwnd == h);
         if (WindowRemoved != null)
             WindowRemoved(this, new WindowEventArgs(window));
         Windows.Remove(window);
     }
 }
Ejemplo n.º 4
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();
 }