public bool IsSystemWindowMatch(SystemWindow Window) { string compareMatchString = MatchString ?? String.Empty; string windowMatchString = String.Empty; switch (MatchUsing) { case MatchUsing.WindowClass: windowMatchString = Window.ClassName; break; case MatchUsing.WindowTitle: windowMatchString = Window.Title; break; case MatchUsing.ExecutableFilename: windowMatchString = Window.Process.MainModule.FileName; break; case MatchUsing.All: return true; } return IsRegEx ? Regex.IsMatch(windowMatchString, compareMatchString, RegexOptions.Singleline | RegexOptions.IgnoreCase) : windowMatchString.Trim().ToLower() == compareMatchString.Trim().ToLower(); }
public PointInfo(List<Point> touchLocation, List<List<Point>> points) { _touchLocation = touchLocation; _window = SystemWindow.FromPointEx(_touchLocation[0].X, _touchLocation[0].Y, true, false); _windowHandle = _window == null ? IntPtr.Zero : _window.HWnd; Points = points; }
public bool IsSystemWindowMatch(SystemWindow Window) { string compareMatchString = MatchString ?? String.Empty; string windowMatchString = String.Empty; try { switch (MatchUsing) { case MatchUsing.WindowClass: windowMatchString = Window.ClassName; break; case MatchUsing.WindowTitle: windowMatchString = Window.Title; break; case MatchUsing.ExecutableFilename: windowMatchString = Window.Process.MainModule.ModuleName; break; case MatchUsing.All: return true; } return IsRegEx ? Regex.IsMatch(windowMatchString, compareMatchString, RegexOptions.Singleline | RegexOptions.IgnoreCase) : String.Equals(windowMatchString.Trim(), compareMatchString.Trim(), StringComparison.CurrentCultureIgnoreCase); } catch { return false; } }
internal override void Update(TreeNodeData tnd, bool allowUnsafeChanges, MainForm mf) { this.mf = mf; this.allowUnsafeChanges = allowUnsafeChanges; currentWindow = ((WindowData)tnd).Window; UpdateControls(); }
private void parseChildren(List<string> toFill, SystemWindow window) { foreach (SystemWindow child in window.AllChildWindows) { string clazz = child.ClassName; if (!toFill.Contains(clazz)) toFill.Add(clazz); parseChildren(toFill, child); } }
void timer_Tick(object sender, EventArgs e) { if (IntPtr.Zero != windowToSnap) { SystemWindow win = new SystemWindow(windowToSnap); win.Location = zone.Location; win.Size = zone.Size; windowToSnap = IntPtr.Zero; } timer.Stop(); }
private void appendContent(StringBuilder sb, SystemWindow sw, WindowContent c) { if (c == null) { sb.AppendLine("<Unknown Type>"); return; } sb.AppendLine(c.ShortDescription); sb.AppendLine("Class Name: " + sw.ClassName); String ldesc = c.LongDescription.Replace("\n", "\r\n").Replace("\r\r\n", "\r\n"); if (ldesc != null && c.ShortDescription != ldesc) { sb.AppendLine("------------------------------------------------------------"); sb.AppendLine(ldesc); } }
public void guess(IGuesserListener listener, SystemWindow window) { string file; try { file = window.Process.MainModule.FileName; } catch (Win32Exception) { listener.guessInfo(2, "*** File access denied"); return; } listener.guessInfo(2, "*** Detected File: " + file); ctrl.guessFile(listener, file); }
private void Highlight(SystemWindow sw, SystemAccessibleObject acc) { if (sw == null) return; if (acc != null && acc != highlightedObject) { if (highlightedWindow != null) highlightedWindow.Refresh(); acc.Highlight(); } else if (sw != highlightedWindow) { if (highlightedWindow != null) highlightedWindow.Refresh(); sw.Highlight(); } highlightedObject = acc; highlightedWindow = sw; }
public void guess(IGuesserListener listener, SystemWindow window) { string mainclass = window.ClassName; List<string> childClasses = new List<string>(); childClasses.Add(mainclass); parseChildren(childClasses, window); childClasses.Sort(); listener.guessInfo(1, "** Main class: " + mainclass); foreach (string c in childClasses) { listener.guessInfo(2, "*** Child class:" + c); } IList<string> results = sp.parse(mainclass, childClasses.ToArray()); foreach (string r in results) { listener.guessInfo(0, "Wndclass suggests: " + r); listener.guessAttribute("WNDCLASS", r); } }
private string getWindowProperties(SystemWindow sw) { string content; if (includeContents.Checked) { try { WindowContent cc = sw.Content; if (cc == null) { content = "Unknown"; } else { content = "\"" + cc.ShortDescription + "\"\r\n" + cc.LongDescription.Replace("\n", "\r\n").Replace("\r\r\n", "\r\n"); } } catch (Exception ex) { content = "\"Exception\"\r\n" + ex.ToString(); } } else { content = "(Enable in Options tab if desired)"; } return " Handle:\t\t0x" + sw.HWnd.ToString("x8") + " (" + sw.HWnd + ")\r\n" + " DialogID:\t0x" + sw.DialogID.ToString("x8") + " (" + sw.DialogID + ")\r\n" + " Position:\t\t(" + sw.Position.Left + ", " + sw.Position.Top + "), " + sw.Position.Width + "x" + sw.Position.Height + "\r\n" + " Parent:\t\t" + (sw.Parent == null ? "None" : (sw.ParentSymmetric == null ? "Asymmetric" : "Symmetric") + " 0x" + sw.Parent.HWnd.ToString("x8")) + "\r\n" + " Appearance:\t" + (sw.Enabled ? "Enabled " : "Disabled ") + (sw.Visible ? "Visible" : "Invisible") + "\r\n" + " Changable:\t" + (sw.Movable ? "Movable " : "NotMovable ") + (sw.Resizable ? "Resizable" : "FixedSize") + "\r\n" + " WindowState:\t" + (sw.TopMost ? "TopMost " : "") + sw.WindowState.ToString() + "\r\n" + " Process:\t\t" + sw.Process.ProcessName + " (0x" + sw.Process.Id.ToString("x8") + "), " + "\r\n" + " ClassName:\t\"" + sw.ClassName + "\"\r\n" + " Title:\t\t\"" + sw.Title + "\"\r\n\r\n" + "Content:\t" + content; }
private void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { if (State != CaptureState.Ready || Mode != CaptureMode.Normal || hwnd.Equals(IntPtr.Zero) || Application.OpenForms.Count != 0 && hwnd.Equals(Application.OpenForms[0].Handle)) return; var systemWindow = new SystemWindow(hwnd); var userApp = ApplicationManager.Instance.GetApplicationFromWindow(systemWindow, true); bool flag = userApp != null && (userApp.Any(app => app is UserApplication && ((UserApplication)app).InterceptTouchInput)); _inputTargetWindow.InterceptTouchInput(flag); }
/// <summary> /// Check whether this window is a descendant of <c>ancestor</c> /// </summary> /// <param name="ancestor">The suspected ancestor</param> /// <returns>If this is really an ancestor</returns> public bool IsDescendantOf(SystemWindow ancestor) { return IsChild(ancestor._hwnd, _hwnd); }
public static SystemAccessibleObject FromWindow(SystemWindow window, AccessibleObjectID objectID) { IAccessible iacc = (IAccessible)AccessibleObjectFromWindow(window == null ? IntPtr.Zero : window.HWnd, (uint)objectID, new Guid("{618736E0-3C3D-11CF-810C-00AA00389B71}")); return new SystemAccessibleObject(iacc, 0); }
/// <summary> /// Gets the automation object for a given window. /// This is a COM object implementing the IDispatch interface, commonly /// available from Microsoft Office windows. /// </summary> /// <param name="window">The window</param> public static object COMObjectFromWindow(SystemWindow window) { return AccessibleObjectFromWindow(window == null ? IntPtr.Zero : window.HWnd, OBJID_NATIVEOM, new Guid("{00020400-0000-0000-C000-000000000046}")); }
private static void SnapTo(SystemWindow window, Point point) { /// /// Get curent monitor working area /// Rectangle workRect = Screen.FromPoint(point).WorkingArea; /// /// Snap/unsnap to top (maximize) /// if (point.Y < workRect.Top + OptionsManager.SnapOptions.TopDistance) { if (window.WindowState == FormWindowState.Normal) { // Highligh the snap point AnimateCursorOnWindow(window, point); // Maximize window.WindowState = FormWindowState.Maximized; } } else { // Unsnap from maximized and center window on mouse if (window.WindowState == FormWindowState.Maximized) { window.WindowState = FormWindowState.Normal; window.Location = new Point(point.X - window.Size.Width / 2, point.Y - window.Size.Height / 2); } } /// /// Snap/unsnap on left side /// if (point.X < workRect.Left + OptionsManager.SnapOptions.LeftDistance) { // Only snap window that are not already snaped if (!_leftSnapedWindows.ContainsKey(window) && !_rightSnapedWindows.ContainsKey(window)) { // Highligh the snap point AnimateCursorOnWindow(window, point); // Keep currentWindow position _leftSnapedWindows.Add(window, window.Position); // Snap currentWindow window.Position = new RECT(workRect.Location.X, workRect.Location.Y, workRect.Size.Width / 2, workRect.Size.Height); } } /// /// Snap/unsnap on right side /// else if (point.X > workRect.Right - OptionsManager.SnapOptions.RightDistance) { // Only snap window that are not already snaped if (!_rightSnapedWindows.ContainsKey(window) && !_leftSnapedWindows.ContainsKey(window)) { // Highligh the snap point AnimateCursorOnWindow(window, point); // Keep currentWindow position _rightSnapedWindows.Add(window, window.Position); // Snap currentWindow window.Position = new RECT(workRect.Size.Width / 2, workRect.Location.Y, workRect.Size.Width, workRect.Size.Height); } } /// /// Try to restore from left or right snap zones else if (_leftSnapedWindows.ContainsKey(window)) { // Restore currentWindow size and center window on mouse window.Size = _leftSnapedWindows[window].Size; window.Location = new Point(point.X - window.Size.Width / 2, point.Y - window.Size.Height / 2); _leftSnapedWindows.Remove(window); } else if (_rightSnapedWindows.ContainsKey(window)) { // Restore currentWindow size and center window on mouse window.Size = _rightSnapedWindows[window].Size; window.Location = new Point(point.X - window.Size.Width / 2, point.Y - window.Size.Height / 2); _rightSnapedWindows.Remove(window); } }
private static void ResizeWindow(SystemWindow window, int dx, int dy) { // Do nothing on a maximized window if ((window.Style & WindowStyleFlags.MAXIMIZE) != 0) return; RECT rect = window.Rectangle; int x, y, xsz, ysz; switch (_clickedQuarter) { case WindowsQuarter.DIR_SW: dx = -dx; x = rect.Left - dx; y = rect.Top; break; case WindowsQuarter.DIR_NW: dx = -dx; dy = -dy; x = rect.Left - dx; y = rect.Top - dy; break; case WindowsQuarter.DIR_NE: dy = -dy; x = rect.Left; y = rect.Top - dy; break; case WindowsQuarter.DIR_SE: default: x = rect.Left; y = rect.Top; break; } xsz = rect.Right - rect.Left + dx; ysz = rect.Bottom - rect.Top + dy; // Resize window.Location = new Point(x, y); window.Size = new Size(xsz, ysz); }
private static void MoveWindow(SystemWindow window, int dx, int dy) { // Do nothing on a maximized window if ((window.Style & WindowStyleFlags.MAXIMIZE) != 0) return; // Move Point oldLocation = window.Location; window.Location = new Point(oldLocation.X + dx, oldLocation.Y + dy); }
private static int getArea(SystemWindow sw) { RECT rr = sw.Rectangle; return rr.Height * rr.Width; }
private void ClickButton(SystemWindow systemWindow) { POINT pt = winMessenger.GetWindowCenter(systemWindow); winMessenger.MouseMove(pt.X, pt.Y); Thread.Sleep(100); winMessenger.Click(); }
internal WindowDeviceContext(SystemWindow sw, IntPtr hDC) { this.sw = sw; this.hDC = hDC; }
private SystemTreeView(SystemWindow sw) { this.sw = sw; }
internal SystemTreeViewItem(SystemWindow sw, IntPtr handle) { this.sw = sw; this.handle = handle; }
/// public bool Equals(SystemWindow sw) { if ((object)sw == null) { return false; } return _hwnd == sw._hwnd; }
public static void MouseHook(LowLevelMessage evt, ref bool handled) { LowLevelMouseMessage mevt = evt as LowLevelMouseMessage; if (mevt != null) { MouseButtons moveMouseState = OptionsManager.MoveOptions.mouseButton; MouseButtons resizeMouseState = OptionsManager.ResizeOptions.mouseButton; switch ((MouseState)mevt.Message) { case MouseState.WM_LBUTTONDOWN: case MouseState.WM_RBUTTONDOWN: case MouseState.WM_MBUTTONDOWN: // Get the window to move or resize _currentWindow = GetTopLevel(SystemWindow.FromPoint(mevt.Point.X, mevt.Point.Y)); if (TestMoveKeyModifier() && TestMoveMouseState(mevt)) { // Now we are moving... _isMoving = true; //... from here to somewhere. _previousPoint = mevt.Point; // Set cursor SystemCursor.SetSystemCursor(Cursors.SizeAll); // Prevent event to be forwarded handled = true; } // Check that: // - we are allowed to resize // - we are not moving // - keys and mouse buttons respect the options else if (_currentWindow.Resizable && !_isMoving && TestResizeKeyModifier() && TestResizeMouseState(mevt)) { // Now we are resizing... _isResizing = true; //... from this point/quarter. _previousPoint = mevt.Point; _clickedQuarter = GetQuarterFromPoint(_currentWindow, mevt.Point); // Set cursor if ((_clickedQuarter == WindowsQuarter.DIR_NW) || (_clickedQuarter == WindowsQuarter.DIR_SE)) SystemCursor.SetSystemCursor(Cursors.SizeNWSE); else if ((_clickedQuarter == WindowsQuarter.DIR_NE) || (_clickedQuarter == WindowsQuarter.DIR_SW)) SystemCursor.SetSystemCursor(Cursors.SizeNESW); // Prevent event to be forwarded handled = true; } break; case MouseState.WM_MOUSEMOVE: if (_isMoving) { int dx = mevt.Point.X - _previousPoint.X; int dy = mevt.Point.Y - _previousPoint.Y; // Only move not left/right snaped window if (!_leftSnapedWindows.ContainsKey(_currentWindow) && !_rightSnapedWindows.ContainsKey(_currentWindow)) MoveWindow(_currentWindow, dx, dy); _previousPoint = mevt.Point; // Snap/Unsnap SnapTo(_currentWindow, mevt.Point); } else if (_isResizing) { int dx = mevt.Point.X - _previousPoint.X; int dy = mevt.Point.Y - _previousPoint.Y; // Resize current window ResizeWindow(_currentWindow, dx, dy); _previousPoint = mevt.Point; } break; case MouseState.WM_LBUTTONUP: case MouseState.WM_RBUTTONUP: case MouseState.WM_MBUTTONUP: if (TestMoveMouseState(mevt)) { if (_isMoving) { // Prevent event to be forwarded handled = true; // Restore cursor SystemCursor.RestoreSystemCursor(); } _isMoving = false; } else if (TestResizeMouseState(mevt)) { if (_isResizing) { // Prevent event to be forwarded handled = true; // Restore cursor SystemCursor.RestoreSystemCursor(); } _isResizing = false; } break; case MouseState.WM_LBUTTONDBLCLK: case MouseState.WM_RBUTTONDBLCLK: case MouseState.WM_MBUTTONDBLCLK: break; case MouseState.WM_MOUSEWHEEL: case MouseState.WM_MOUSEHWHEEL: break; } //if (message.Length != 0) // Console.WriteLine("[Mouse] msg:" + message // + " pt:" + "(" + mevt.Point.X + "," + mevt.Point.Y + ")" // + " mouseData:" + mevt.MouseData // + " time:" + mevt.Time // + " dwExtraInfo:" + mevt.ExtraInfo); } }
/// <summary> /// Returns all toplevel windows that match the given predicate. /// </summary> /// <param name="predicate">The predicate to filter.</param> /// <returns>The filtered toplevel windows</returns> public static SystemWindow[] FilterToplevelWindows(Predicate<SystemWindow> predicate) { List<SystemWindow> wnds = new List<SystemWindow>(); EnumWindows(new EnumWindowsProc(delegate(IntPtr hwnd, IntPtr lParam) { SystemWindow tmp = new SystemWindow(hwnd); if (predicate(tmp)) wnds.Add(tmp); return 1; }), new IntPtr(0)); return wnds.ToArray(); }
private static void AnimateCursorOnWindow(SystemWindow window, Point point) { new Thread(new ThreadStart(delegate { // Create a device context that cover the whole display (all monitors) IntPtr hDC = CreateDC("DISPLAY", "", "", IntPtr.Zero); // Get a graphics using (Graphics g = Graphics.FromHdc(hDC)) { const int radius = 30; g.SmoothingMode = SmoothingMode.AntiAlias; g.CompositingMode = CompositingMode.SourceOver; g.Clip = new Region(new Rectangle(point.X - (radius + 10) / 2, point.Y - (radius + 10) / 2, radius + 10, radius + 10)); // Draw a growing circle upon the cursor Brush trans = Brushes.Transparent; Pen penGr = new Pen(Color.LightGray, 1); Pen penDG = new Pen(Color.DimGray, 1); Pen penLG = new Pen(Color.LightGray, 1); for (int j = 0; j < 2; j++) { for (int i = 0; i < radius; i+=2) { Rectangle ellRect = new Rectangle(point.X - i / 2, point.Y - i / 2, i, i); g.FillEllipse(trans, ellRect); ellRect.Inflate(1, 1); g.DrawEllipse(penGr, ellRect); ellRect.Inflate(1, 1); g.DrawEllipse(penDG, ellRect); ellRect.Inflate(1, 1); g.DrawEllipse(penLG, ellRect); //g.Clear(Color.Transparent); window.Refresh(); } window.Refresh(); } } // Delete the device context DeleteDC(hDC); } )).Start(); }
/// <summary> /// Returns all child windows that match the given predicate. /// </summary> /// <param name="directOnly">Whether to include only direct children (no descendants)</param> /// <param name="predicate">The predicate to filter.</param> /// <returns>The list of child windows.</returns> public SystemWindow[] FilterDescendantWindows(bool directOnly, Predicate<SystemWindow> predicate) { List<SystemWindow> wnds = new List<SystemWindow>(); EnumChildWindows(_hwnd, delegate(IntPtr hwnd, IntPtr lParam) { SystemWindow tmp = new SystemWindow(hwnd); bool add = true; if (directOnly) { add = tmp.Parent._hwnd == _hwnd; } if (add && predicate(tmp)) wnds.Add(tmp); return 1; }, new IntPtr(0)); return wnds.ToArray(); }
private static WindowsQuarter GetQuarterFromPoint(SystemWindow window, Point point) { WindowsQuarter[,] dirs = {{WindowsQuarter.DIR_NW, WindowsQuarter.DIR_SW}, {WindowsQuarter.DIR_NE, WindowsQuarter.DIR_SE}}; RECT rect = window.Rectangle; int horiz = (Math.Abs(point.X - rect.Left) < Math.Abs(point.X - rect.Right)) ? 0 : 1; int vert = (Math.Abs(point.Y - rect.Top) < Math.Abs(point.Y - rect.Bottom)) ? 0 : 1; return dirs[horiz, vert]; }
internal void HideWindow(SystemWindow window) { ShowWindow(window.HWnd, SW_HIDE); }
private static SystemWindow GetTopLevel(SystemWindow window) { if (window.ParentSymmetric == null) return window; return GetTopLevel(window.ParentSymmetric); }
private void window_Deactivated(object sender, EventArgs e) { var win = new ManagedWinapi.Windows.SystemWindow(new WindowInteropHelper(this).Handle); if ((win.Style & WindowStyleFlags.DISABLED) != WindowStyleFlags.DISABLED) { WindowState = System.Windows.WindowState.Minimized; tbInput.Text = string.Empty; } }