public static SystemInterop.RECT GetWorkingArea() { IntPtr ptr = IntPtr.Zero; SystemInterop.RECT rect = new SystemInterop.RECT(); SystemInterop.SystemParametersInfo(SystemInterop.SPI.SPI_GETWORKAREA, 0, ref rect, SystemInterop.SPIF.SPIF_UPDATEINIFILE); return(rect); }
public static void SetWorkingArea(int left, int top, int right, int bottom) { IntPtr ptr = IntPtr.Zero; SystemInterop.RECT rect = new SystemInterop.RECT() { Left = left, Top = top, Right = right, Bottom = bottom }; SystemInterop.SystemParametersInfo(SystemInterop.SPI.SPI_SETWORKAREA, 0, ref rect, SystemInterop.SPIF.SPIF_UPDATEINIFILE); }
public static void SetWorkingArea(int left, int top, int right, int bottom) { IntPtr ptr = IntPtr.Zero; SystemInterop.RECT rect = new SystemInterop.RECT() { Left = left, Top = top, Right = right, Bottom = bottom }; bool success = SystemInterop.SystemParametersInfo(SystemInterop.SPI.SPI_SETWORKAREA, 0, ref rect, SystemInterop.SPIF.SPIF_CHANGE); if (!success) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }
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(); }