/// <summary> /// Handles click on the Main button. By default shows/hides Buttonstack, /// with CTRL pressed shows Run dialog instead, and with CTRL+SHIFT in DEBUG /// mode shows RestartExplorer instance for purposes of localization /// </summary> private void ShowButtonStack(object sender, RoutedEventArgs e) { if (!BtnStck.IsInstantited) { return; } KillArrow(); if ((Control.ModifierKeys & Keys.Control) > 0) { #if DEBUG if ((Control.ModifierKeys & Keys.Shift) > 0) { new RestartExplorer().ShowDialog(); return; } #endif ShowRunDialog(this, null); return; } MfuList.UpdateStartMfu(); BtnStck.Instance.Show();//XP:955ms 0_o var screenPoint = new API.POINT(); API.GetCursorPos(ref screenPoint); GetSetWndPosition(BtnStck.Instance, screenPoint, sender == Keyboard.PrimaryDevice && SettingsManager.Instance.AltZAutoCornerEnabled); // ^^^ means "Command came from KB and Auto-cornering enabled" }
public void FillPolygon(IList <Point> Points, ILineStyleInfo LineStyle, IFillStyleInfo FillStyle) { GDILineStyle Line = (GDILineStyle)LineStyle; GDIFillStyle Fill = (GDIFillStyle)FillStyle; API.POINT[] P = new API.POINT[Points.Count]; for (int i = 0; i < Points.Count; i++) { P[i].x = Points[i].X; P[i].y = Points[i].Y; } SetPenBrush(Line.ForeColor, Line.Width, Fill.FillColor); //IntPtr hPen = API.CreatePen(0, Line.Width, Line.Win32ForeColor); //IntPtr hOldPen = API.SelectObject(hDC, hPen); //IntPtr hBrush = API.CreateSolidBrush(Fill.Win32FillColor); //IntPtr hOldBrush = API.SelectObject(hDC, hBrush); API.Polygon(hDC, P, Points.Count); ResetPenBrush(); //API.SelectObject(hDC, hOldBrush); //API.DeleteObject(hBrush); //API.SelectObject(hDC, hOldPen); //API.DeleteObject(hPen); }
public void EnumWindowsTest() { Console.Clear(); API.EnumWindowsProc ewp = new API.EnumWindowsProc(enumWindowProc); API.EnumWindows(ewp, 0); API.POINT pt = new API.POINT(100, 100); System.Drawing.Point pt1 = pt; }
// ReSharper restore UnusedParameter.Local /// <summary> /// Locates the window passed as if it is a Progman, the Start Menu. /// First, by screenPoint passed calculates active screen. /// By it's bounds determines the location of TaskBar. /// Finally, calculates the position of target window. /// Shows window except if it is a Placement rectangle. /// Focuses window if it is a ButtonStack. /// </summary> /// <param name="w">Window to locate</param> /// <param name="screenPoint">Unmanaged struct containing absolute screen coordinates, in px.</param> /// <param name="ignoreTaskbarPosition">Flag instructing method to ignore the location of task bar /// locating w simply in the corner closest to the screenPoint. E.g. to show BtnStck by Alt+Z.</param> private static void GetSetWndPosition(Window w, API.POINT screenPoint, bool ignoreTaskbarPosition) { //On Windows10 WPF apps are painted with gaps on all sides. The gap at the top is additionaly painted white. var modifier = Util.OsIs.TenOrMore ? 6 : 0; var resPoint = new Point(); var screen = Screen.FromPoint(new System.Drawing.Point(screenPoint.X, screenPoint.Y)); //We show stack in the corner closest to the mouse bool isHideTaskBarOptionOn = (screen.WorkingArea.Width == screen.Bounds.Width && screen.WorkingArea.Height == screen.Bounds.Height) || ignoreTaskbarPosition; //taskbar is vertical @ left or horizontal if ((isHideTaskBarOptionOn && screenPoint.X <= screen.WorkingArea.X + screen.WorkingArea.Width / 2) || screen.WorkingArea.X > screen.Bounds.X || (screen.WorkingArea.Width == screen.Bounds.Width & !isHideTaskBarOptionOn)) { resPoint.X = screen.WorkingArea.X - modifier * SystemScale; } else //vertical @ right { resPoint.X = (screen.WorkingArea.Width + screen.WorkingArea.X - (w.Width - modifier) * SystemScale) / SystemScale; } //taskbar is horizontal @ top or vertical if ((isHideTaskBarOptionOn && screenPoint.Y <= screen.WorkingArea.Y + screen.WorkingArea.Height / 2) || screen.WorkingArea.Y > screen.Bounds.Y || (screen.WorkingArea.Height == screen.Bounds.Height & !isHideTaskBarOptionOn)) { resPoint.Y = screen.WorkingArea.Y; //No modification is applied here because windows reneders this white bar. } else //horizontal @ bottom { resPoint.Y = (screen.WorkingArea.Height + screen.WorkingArea.Y - (w.Height - modifier) * SystemScale) / SystemScale; } w.Left = resPoint.X; w.Top = resPoint.Y; // ReSharper disable PossibleUnintendedReferenceComparison if (w != PlacementWnd) { w.Activate(); } // ReSharper restore PossibleUnintendedReferenceComparison var b = w as BtnStck; if (b != null) { b.Focus();//Focus() is __new on ButtonStack, must explicitly type } }
// ReSharper restore UnusedParameter.Local /// <summary> /// Locates the window passed as if it is a Progman, the Start Menu. /// First, by screenPoint passed calculates active screen. /// By it's bounds determines the location of TaskBar. /// Finally, calculates the position of target window. /// Shows window except if it is a Placement rectangle. /// Focuses window if it is a ButtonStack. /// </summary> /// <param name="w">Window to locate</param> /// <param name="screenPoint">Unmanaged struct containing absolute screen coordinates, in px.</param> /// <param name="ignoreTaskbarPosition">Flag instructing method to ignore the location of task bar /// locating w simply in the corner closest to the screenPoint. E.g. to show BtnStch by Alt+Z.</param> private static void GetSetWndPosition(Window w, API.POINT screenPoint, bool ignoreTaskbarPosition) { var resPoint = new Point(); var screen = Screen.FromPoint(new System.Drawing.Point(screenPoint.X, screenPoint.Y)); //We show stack in the corner closest to the mouse bool isHideTaskBarOptionOn = (screen.WorkingArea.Width == screen.Bounds.Width && screen.WorkingArea.Height == screen.Bounds.Height) || ignoreTaskbarPosition; //taskbar is vertical @ left or horizontal if ((isHideTaskBarOptionOn && screenPoint.X <= screen.WorkingArea.X + screen.WorkingArea.Width / 2) || screen.WorkingArea.X > screen.Bounds.X || (screen.WorkingArea.Width == screen.Bounds.Width & !isHideTaskBarOptionOn)) { resPoint.X = screen.WorkingArea.X; } else //vertical @ right { resPoint.X = (screen.WorkingArea.Width + screen.WorkingArea.X - w.Width * SystemScale) / SystemScale; } //taskbar is horizontal @ top or vertical if ((isHideTaskBarOptionOn && screenPoint.Y <= screen.WorkingArea.Y + screen.WorkingArea.Height / 2) || screen.WorkingArea.Y > screen.Bounds.Y || (screen.WorkingArea.Height == screen.Bounds.Height & !isHideTaskBarOptionOn)) { resPoint.Y = screen.WorkingArea.Y; } else //horizontal @ bottom { resPoint.Y = (screen.WorkingArea.Height + screen.WorkingArea.Y - w.Height * SystemScale) / SystemScale; } w.Left = resPoint.X; w.Top = resPoint.Y; // ReSharper disable PossibleUnintendedReferenceComparison if (w != PlacementWnd) { w.Activate(); } // ReSharper restore PossibleUnintendedReferenceComparison var b = w as BtnStck; if (b != null) { b.Focus();//Focus() is __new on ButtonStack, must explicitly type } }
public void WindowFromPointTest() { API.POINT pt = new API.POINT(200, 200); IntPtr ptr = API.WindowFromPoint(pt); if (ptr != IntPtr.Zero) { Int32 txtLength = API.GetWindowTextLength(ptr); StringBuilder sb = new StringBuilder("", txtLength + 2); Int32 tCount = API.GetWindowText(ptr, sb, sb.Capacity); Console.WriteLine(sb.ToString()); Console.WriteLine("获取文本数:" + tCount); } else { Console.WriteLine("未找到窗口!"); } }