private static void MouseHook_MouseUpEvent(object sender, MouseEventArgs e) { if (filter.Spying) { filter.picSpy.Image = Properties.Resources.Spy.ToBitmap(); shadow.Cursor = Cursors.Default; filter.Spying = false; IntPtr handle = WindowFromPoint(e.Location); WindowsInfoHelper.GetTopWindow(ref handle); filter.FillInfo(handle); } if (canDock) { hForegroundWindow = GetForegroundWindow(); DwmGetWindowAttribute(hForegroundWindow, DWMWA_EXTENDED_FRAME_BOUNDS, out Rect rectFrame, Marshal.SizeOf(typeof(Rect))); GetWindowRect(hForegroundWindow, out Rect rectWindow); int shadowWidth = ((rectWindow.Right - rectWindow.Left) - (rectFrame.Right - rectFrame.Left)) / 2; int shadowHeight = ((rectWindow.Bottom - rectWindow.Top) - (rectFrame.Bottom - rectFrame.Top)); Task.Run(() => { Thread.Sleep(100); SetWindowPos(hForegroundWindow, IntPtr.Zero, rectDockArea.X - shadowWidth, rectDockArea.Y, rectDockArea.Width + shadowWidth * 2, rectDockArea.Height + shadowHeight, 0); }); shadow.ClearShadow(); } shallDock = false; }
private static void MouseHook_MouseDownEvent(object sender, MouseEventArgs e) { hCurrentWindow = WindowFromPoint(e.Location); WindowsInfoHelper.GetTopWindow(ref hCurrentWindow); GetWindowRect(hCurrentWindow, out rectCurrentWindow); WindowsInfoHelper.WindowInfo currentWindow = new WindowsInfoHelper.WindowInfo(hCurrentWindow); foreach (XmlElement xe in xeFilters) { string windowClass = ((XmlElement)xe.SelectSingleNode("WindowClass")).GetAttribute("Text"); string windowTitle = ((XmlElement)xe.SelectSingleNode("WindowTitle")).GetAttribute("Text"); string windowTitleLogic = ((XmlElement)xe.SelectSingleNode("WindowTitle")).GetAttribute("Logic"); string filePath = ((XmlElement)xe.SelectSingleNode("FilePath")).GetAttribute("Text"); if (currentWindow.WindowClass == windowClass && string.Equals(currentWindow.FilePath, filePath, StringComparison.OrdinalIgnoreCase) && ((windowTitleLogic == "Include" && currentWindow.WindowTitle.Contains(windowTitle)) || (windowTitleLogic == "Equal" && currentWindow.WindowTitle == windowTitle))) { shallDock = false; return; } } if (hCurrentWindow == dock.Handle || hCurrentWindow == filter.Handle) { shallDock = false; return; } shallDock = true; }
private static void MouseHook_MouseWheelEvent(object sender, MouseEventArgs e) { if (shallDock) { shallSmartDock = true; SmartDockPoint = e.Location; rectWorkingArea = Screen.FromPoint(SmartDockPoint).WorkingArea; hForegroundWindow = GetForegroundWindow(); windows = WindowsInfoHelper.GetVisibleWindowsInfo(); Region allRemainRegion = GetAllRemainRegion(hForegroundWindow, rectWorkingArea); List <RectangleF> allRemainRegionScans = new List <RectangleF>(allRemainRegion.GetRegionScans(matrix)); topWindows.Clear(); foreach (WindowsInfoHelper.WindowInfo item in windows) { if (!IsEntirelyCovered(item.Handle) && item.Handle != hForegroundWindow) { topWindows.Add(item.Handle); } } bool isChanged = false; if (IsListChanged(allRemainRegionScans, lastAllRemainRegionScans) || IsListChanged(topWindows, lastTopWindows)) { isChanged = true; lastAllRemainRegionScans = new List <RectangleF>(allRemainRegionScans.ToArray()); lastTopWindows = new List <IntPtr>(topWindows.ToArray()); } if (hLastSmartDockWindow != hForegroundWindow || isChanged) { hLastSmartDockWindow = hForegroundWindow; lastSmartDockWindowIndex = 0; rectSmartDocks.Clear(); foreach (RectangleF item in allRemainRegionScans) { if (!(item.X == rectWorkingArea.X && item.Y == rectWorkingArea.Y && item.Width == rectWorkingArea.Width && item.Height == rectWorkingArea.Height)) { Region rContainer = allRemainRegion.Clone(); rContainer.Intersect(new RectangleF(item.X, rectWorkingArea.Y, item.Width, rectWorkingArea.Height)); foreach (RectangleF rectPiece in rContainer.GetRegionScans(matrix)) { if (rectPiece.Width < 200 || rectPiece.Height < 200) { continue; } rectSmartDocks.Add(new Rectangle((int)rectPiece.X, (int)rectPiece.Y, (int)rectPiece.Width, (int)rectPiece.Height)); } } } for (int i = rectSmartDocks.Count - 1; i > -1; i--) { for (int j = rectSmartDocks.Count - 1; j > -1; j--) { if (HasLargePiece(rectSmartDocks[i], rectSmartDocks[j]) && i != j) { rectSmartDocks.RemoveAt(i); break; } } } List <Rectangle> listTopRectSmartDock = new List <Rectangle>(); foreach (IntPtr item in topWindows) { Region remainRegion = GetRemainRegion(item, rectWorkingArea); foreach (RectangleF scans in remainRegion.GetRegionScans(matrix)) { if (!(scans.X == rectWorkingArea.X && scans.Y == rectWorkingArea.Y && scans.Width == rectWorkingArea.Width && scans.Height == rectWorkingArea.Height)) { Region rContainer = remainRegion.Clone(); rContainer.Intersect(new RectangleF(scans.X, rectWorkingArea.Y, scans.Width, rectWorkingArea.Height)); foreach (RectangleF rectPiece in rContainer.GetRegionScans(matrix)) { if (rectPiece.Width < 200 || rectPiece.Height < 200) { continue; } listTopRectSmartDock.Add(new Rectangle((int)rectPiece.X, (int)rectPiece.Y, (int)rectPiece.Width, (int)rectPiece.Height)); } } } } for (int i = listTopRectSmartDock.Count - 1; i > -1; i--) { for (int j = listTopRectSmartDock.Count - 1; j > -1; j--) { if (HasLargePiece(listTopRectSmartDock[i], listTopRectSmartDock[j]) && i != j) { listTopRectSmartDock.RemoveAt(i); break; } } } foreach (Rectangle item in listTopRectSmartDock) { bool hasThis = false; foreach (Rectangle smartDock in rectSmartDocks) { if (smartDock.X == item.X && smartDock.Y == item.Y && smartDock.Width == item.Width && smartDock.Height == item.Height) { hasThis = true; } } if (!hasThis) { rectSmartDocks.Add(item); } } rectSmartDocks.Insert(0, rectWorkingArea); } if (e.Delta < 0) { lastSmartDockWindowIndex++; if (lastSmartDockWindowIndex == rectSmartDocks.Count) { lastSmartDockWindowIndex = 0; } } else { lastSmartDockWindowIndex--; if (lastSmartDockWindowIndex == -1) { lastSmartDockWindowIndex = rectSmartDocks.Count - 1; } } shadow.FillShadow(rectSmartDocks[lastSmartDockWindowIndex]); rectDockArea = rectSmartDocks[lastSmartDockWindowIndex]; canDock = true; } }
private static void MouseHook_MouseMoveEvent(object sender, MouseEventArgs e) { if (shallSmartDock) { if ((e.X - SmartDockPoint.X) * (e.X - SmartDockPoint.X) + (e.Y - SmartDockPoint.Y) * (e.Y - SmartDockPoint.Y) > 512) { shallSmartDock = false; } } else { rectWorkingArea = Screen.FromPoint(e.Location).WorkingArea; int x = e.X < rectWorkingArea.X ? rectWorkingArea.X : e.X; int y = e.Y < rectWorkingArea.Y ? rectWorkingArea.Y : e.Y; x = x > rectWorkingArea.Width + rectWorkingArea.X ? rectWorkingArea.Width + rectWorkingArea.X : x; y = y > rectWorkingArea.Height + rectWorkingArea.Y ? rectWorkingArea.Height + rectWorkingArea.Y : y; hForegroundWindow = GetForegroundWindow(); WindowsInfoHelper.GetTopWindow(ref hForegroundWindow); GetWindowRect(hForegroundWindow, out Rect rectForegroundWindow); if (shallDock && ((hCurrentWindow == hForegroundWindow) && ((rectCurrentWindow.Left != rectForegroundWindow.Left || rectCurrentWindow.Top != rectForegroundWindow.Top) && (rectCurrentWindow.Bottom - rectCurrentWindow.Top == rectForegroundWindow.Bottom - rectForegroundWindow.Top && rectCurrentWindow.Right - rectCurrentWindow.Left == rectForegroundWindow.Right - rectForegroundWindow.Left)))) { foreach (XmlElement xe in xeDocks) { XmlElement xeTrigger = (XmlElement)xe.SelectSingleNode("Trigger"); XmlElement xeDock = (XmlElement)xe.SelectSingleNode("Dock"); Rectangle rectTrigger = ConvertRealRect(Convert.ToInt32(xeTrigger.GetAttribute("Top")), Convert.ToInt32(xeTrigger.GetAttribute("Bottom")), Convert.ToInt32(xeTrigger.GetAttribute("Left")), Convert.ToInt32(xeTrigger.GetAttribute("Right"))); if (rectTrigger.Contains(x, y)) { canDock = true; rectDockArea = ConvertRealRect((xeDock.GetAttribute("Top") != "-" ? Convert.ToInt32(xeDock.GetAttribute("Top")) : 0), (xeDock.GetAttribute("Bottom") != "-" ? Convert.ToInt32(xeDock.GetAttribute("Bottom")) : 100), (xeDock.GetAttribute("Left") != "-" ? Convert.ToInt32(xeDock.GetAttribute("Left")) : 0), (xeDock.GetAttribute("Right") != "-" ? Convert.ToInt32(xeDock.GetAttribute("Right")) : 100)); if (xeDock.GetAttribute("Top") == "-") { rectDockArea = new Rectangle(rectDockArea.X, rectForegroundWindow.Top, rectDockArea.Width, rectDockArea.Height - rectForegroundWindow.Top + rectWorkingArea.Y); } if (xeDock.GetAttribute("Bottom") == "-") { rectDockArea = new Rectangle(rectDockArea.X, rectDockArea.Y, rectDockArea.Width, rectForegroundWindow.Bottom - rectDockArea.Y); } if (xeDock.GetAttribute("Left") == "-") { rectDockArea = new Rectangle(rectForegroundWindow.Left, rectDockArea.Y, rectDockArea.Width - rectForegroundWindow.Left + rectWorkingArea.X, rectDockArea.Height); } if (xeDock.GetAttribute("Right") == "-") { rectDockArea = new Rectangle(rectDockArea.X, rectDockArea.Y, rectForegroundWindow.Right - rectDockArea.X, rectDockArea.Height); } shadow.FillShadow(rectDockArea); return; } } } canDock = false; shadow.ClearShadow(); } }