Esempio n. 1
0
        /// <summary>
        /// Recalculates OS coordinates in order to support WPFs coordinate
        /// system if OS scaling (DPIs) is not 100%.
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        private Point GetDeviceCoordinates(Point point)
        {
            if (double.IsNaN(scalingFactor))
            {
                //calculate scaling factor in order to support non-standard DPIs
                var presentationSource = PresentationSource.FromVisual(this);
                if (presentationSource == null)
                {
                    scalingFactor = 1;
                }
                else
                {
                    var transform = presentationSource.CompositionTarget.TransformToDevice;
                    scalingFactor = 1 / transform.M11;
                }
            }

            //on standard DPI settings, just return the point
            if (scalingFactor == 1.0)
            {
                return(point);
            }

            return(new Point()
            {
                X = (int)(point.X / SystemInfo.DpiXFactor), Y = (int)(point.Y / SystemInfo.DpiYFactor)
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Displays the <see cref="TrayPopup"/> control if
        /// it was set.
        /// </summary>
        private void ShowTrayPopup(Point cursorPosition)
        {
            if (IsDisposed)
            {
                return;
            }

            //raise preview event no matter whether popup is currently set
            //or not (enables client to set it on demand)
            var args = RaisePreviewTrayPopupOpenEvent();

            if (args.Handled)
            {
                return;
            }

            if (TrayPopup != null)
            {
                //use absolute position, but place the popup centered above the icon
                TrayPopupResolved.Placement        = PlacementMode.AbsolutePoint;
                TrayPopupResolved.HorizontalOffset = cursorPosition.X;
                TrayPopupResolved.VerticalOffset   = cursorPosition.Y;

                //open popup
                TrayPopupResolved.IsOpen = true;

                IntPtr handle = IntPtr.Zero;
                if (TrayPopupResolved.Child != null)
                {
                    //try to get a handle on the popup itself (via its child)
                    HwndSource source = (HwndSource)PresentationSource.FromVisual(TrayPopupResolved.Child);
                    if (source != null)
                    {
                        handle = source.Handle;
                    }
                }

                //if we don't have a handle for the popup, fall back to the message sink
                if (handle == IntPtr.Zero)
                {
                    handle = messageSink.MessageWindowHandle;
                }

                //activate either popup or message sink to track deactivation.
                //otherwise, the popup does not close if the user clicks somewhere else
                Win32.Win32.SetForegroundWindow(handle);

                //raise attached event - item should never be null unless developers
                //changed the CustomPopup directly...
                if (TrayPopup != null)
                {
                    RaisePopupOpenedEvent(TrayPopup);
                }

                //bubble routed event
                RaiseTrayPopupOpenEvent();
            }
        }
Esempio n. 3
0
 public static bool Click(Win32.POINT point, int nbClick = 1, int delay = 20)
 {
     if (bshandle == IntPtr.Zero)
     {
         bshandle = GetBlueStacksWindowHandle();
     }
     if (bshandle == IntPtr.Zero)
     {
         return(false);
     }
     return(MouseHelper.ClickOnPoint2(bshandle, point, nbClick, delay));
 }
Esempio n. 4
0
        /// <summary>
        /// Displays the <see cref="ContextMenu"/> if
        /// it was set.
        /// </summary>
        private void ShowContextMenu(Point cursorPosition)
        {
            if (IsDisposed)
            {
                return;
            }

            //raise preview event no matter whether context menu is currently set
            //or not (enables client to set it on demand)
            var args = RaisePreviewTrayContextMenuOpenEvent();

            if (args.Handled)
            {
                return;
            }

            if (ContextMenu != null)
            {
                //use absolute positioning. We need to set the coordinates, or a delayed opening
                //(e.g. when left-clicked) opens the context menu at the wrong place if the mouse
                //is moved!
                ContextMenu.Placement        = PlacementMode.AbsolutePoint;
                ContextMenu.HorizontalOffset = cursorPosition.X;
                ContextMenu.VerticalOffset   = cursorPosition.Y;
                ContextMenu.IsOpen           = true;

                IntPtr handle = IntPtr.Zero;

                //try to get a handle on the context itself
                HwndSource source = (HwndSource)PresentationSource.FromVisual(ContextMenu);
                if (source != null)
                {
                    handle = source.Handle;
                }

                //if we don't have a handle for the popup, fall back to the message sink
                if (handle == IntPtr.Zero)
                {
                    handle = messageSink.MessageWindowHandle;
                }

                //activate the context menu or the message window to track deactivation - otherwise, the context menu
                //does not close if the user clicks somewhere else. With the message window
                //fallback, the context menu can't receive keyboard events - should not happen though
                Win32.Win32.SetForegroundWindow(handle);

                //bubble event
                RaiseTrayContextMenuOpenEvent();
            }
        }
Esempio n. 5
0
 public static extern IntPtr WindowFromPoint(POINT point);
Esempio n. 6
0
 public static extern int DragDetect(HWND hwnd, POINT pt);
Esempio n. 7
0
 public static extern int PolyPolyline(HDC hdc, ref POINT lppt, ref int lpdwPolyPoints, int cCount);
Esempio n. 8
0
 public static extern int SetViewportOrgEx(HDC hdc, int nX, int nY, ref POINT lpPoint);
Esempio n. 9
0
 public static extern IntPtr WindowFromPoint(POINT Point);
Esempio n. 10
0
 public static extern int PolylineTo(HDC hdc, ref POINT lppt, int cCount);
Esempio n. 11
0
 public static extern int MoveToEx(HDC hdc, int x, int y, ref POINT lpPoint);
Esempio n. 12
0
 public static extern bool GetPhysicalCursorPos(ref POINT lpPoint);
Esempio n. 13
0
        /// <summary>
        /// Shows a custom control as a tooltip in the tray location.
        /// </summary>
        /// <param name="balloon"></param>
        /// <param name="animation">An optional animation for the popup.</param>
        /// <param name="timeout">The time after which the popup is being closed.
        /// Submit null in order to keep the balloon open inde
        /// </param>
        /// <exception cref="ArgumentNullException">If <paramref name="balloon"/>
        /// is a null reference.</exception>
        public void ShowCustomBalloon(UIElement balloon, PopupAnimation animation, int?timeout)
        {
            Dispatcher dispatcher = this.GetDispatcher();

            if (!dispatcher.CheckAccess())
            {
                var action = new Action(() => ShowCustomBalloon(balloon, animation, timeout));
                dispatcher.Invoke(DispatcherPriority.Normal, action);
                return;
            }

            if (balloon == null)
            {
                throw new ArgumentNullException("balloon");
            }
            if (timeout.HasValue && timeout < 500)
            {
                string msg = "Invalid timeout of {0} milliseconds. Timeout must be at least 500 ms";
                msg = String.Format(msg, timeout);
                throw new ArgumentOutOfRangeException("timeout", msg);
            }

            EnsureNotDisposed();

            //make sure we don't have an open balloon
            lock (this)
            {
                CloseBalloon();
            }

            //create an invisible popup that hosts the UIElement
            Popup popup = new Popup();

            popup.AllowsTransparency = true;

            //provide the popup with the taskbar icon's data context
            UpdateDataContext(popup, null, DataContext);

            //don't animate by default - devs can use attached
            //events or override
            popup.PopupAnimation = animation;

            //in case the balloon is cleaned up through routed events, the
            //control didn't remove the balloon from its parent popup when
            //if was closed the last time - just make sure it doesn't have
            //a parent that is a popup
            var parent = LogicalTreeHelper.GetParent(balloon) as Popup;

            if (parent != null)
            {
                parent.Child = null;
            }

            if (parent != null)
            {
                string msg =
                    "Cannot display control [{0}] in a new balloon popup - that control already has a parent. You may consider creating new balloons every time you want to show one.";
                msg = String.Format(msg, balloon);
                throw new InvalidOperationException(msg);
            }

            popup.Child = balloon;

            //don't set the PlacementTarget as it causes the popup to become hidden if the
            //TaskbarIcon's parent is hidden, too...
            //popup.PlacementTarget = this;

            popup.Placement = PlacementMode.AbsolutePoint;
            popup.StaysOpen = true;

            Point position = TrayInfo.GetTrayLocation();

            position = GetDeviceCoordinates(position);
            popup.HorizontalOffset = position.X - 1;
            popup.VerticalOffset   = position.Y - 1;

            //store reference
            lock (this)
            {
                SetCustomBalloon(popup);
            }

            //assign this instance as an attached property
            SetParentTaskbarIcon(balloon, this);

            //fire attached event
            RaiseBalloonShowingEvent(balloon, this);

            //display item
            popup.IsOpen = true;

            if (timeout.HasValue)
            {
                //register timer to close the popup
                balloonCloseTimer.Change(timeout.Value, Timeout.Infinite);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Processes mouse events, which are bubbled
        /// through the class' routed events, trigger
        /// certain actions (e.g. show a popup), or
        /// both.
        /// </summary>
        /// <param name="me">Event flag.</param>
        private void OnMouseEvent(MouseEvent me)
        {
            if (IsDisposed)
            {
                return;
            }

            switch (me)
            {
            case MouseEvent.MouseMove:
                RaiseTrayMouseMoveEvent();
                //immediately return - there's nothing left to evaluate
                return;

            case MouseEvent.IconRightMouseDown:
                RaiseTrayRightMouseDownEvent();
                break;

            case MouseEvent.IconLeftMouseDown:
                RaiseTrayLeftMouseDownEvent();
                break;

            case MouseEvent.IconRightMouseUp:
                RaiseTrayRightMouseUpEvent();
                break;

            case MouseEvent.IconLeftMouseUp:
                RaiseTrayLeftMouseUpEvent();
                break;

            case MouseEvent.IconMiddleMouseDown:
                RaiseTrayMiddleMouseDownEvent();
                break;

            case MouseEvent.IconMiddleMouseUp:
                RaiseTrayMiddleMouseUpEvent();
                break;

            case MouseEvent.IconDoubleClick:
                //cancel single click timer
                singleClickTimer.Change(Timeout.Infinite, Timeout.Infinite);
                //bubble event
                RaiseTrayMouseDoubleClickEvent();
                break;

            case MouseEvent.BalloonToolTipClicked:
                RaiseTrayBalloonTipClickedEvent();
                break;

            default:
                throw new ArgumentOutOfRangeException("me", "Missing handler for mouse event flag: " + me);
            }


            //get mouse coordinates
            Point cursorPosition = new Point();

            if (messageSink.Version == NotifyIconVersion.Vista)
            {
                //physical cursor position is supported for Vista and above
                Win32.Win32.GetPhysicalCursorPos(ref cursorPosition);
            }
            else
            {
                Win32.Win32.GetCursorPos(ref cursorPosition);
            }

            cursorPosition = GetDeviceCoordinates(cursorPosition);

            bool isLeftClickCommandInvoked = false;

            //show popup, if requested
            if (me.IsMatch(PopupActivation))
            {
                if (me == MouseEvent.IconLeftMouseUp)
                {
                    //show popup once we are sure it's not a double click
                    singleClickTimerAction = () =>
                    {
                        LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
                        ShowTrayPopup(cursorPosition);
                    };
                    singleClickTimer.Change(Win32.Win32.GetDoubleClickTime(), Timeout.Infinite);
                    isLeftClickCommandInvoked = true;
                }
                else
                {
                    //show popup immediately
                    ShowTrayPopup(cursorPosition);
                }
            }


            //show context menu, if requested
            if (me.IsMatch(MenuActivation))
            {
                if (me == MouseEvent.IconLeftMouseUp)
                {
                    //show context menu once we are sure it's not a double click
                    singleClickTimerAction = () =>
                    {
                        LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
                        ShowContextMenu(cursorPosition);
                    };
                    singleClickTimer.Change(Win32.Win32.GetDoubleClickTime(), Timeout.Infinite);
                    isLeftClickCommandInvoked = true;
                }
                else
                {
                    //show context menu immediately
                    ShowContextMenu(cursorPosition);
                }
            }

            //make sure the left click command is invoked on mouse clicks
            if (me == MouseEvent.IconLeftMouseUp && !isLeftClickCommandInvoked)
            {
                //show context menu once we are sure it's not a double click
                singleClickTimerAction =
                    () =>
                {
                    LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
                };
                singleClickTimer.Change(Win32.Win32.GetDoubleClickTime(), Timeout.Infinite);
            }
        }
Esempio n. 15
0
 public static extern int DragQueryPoint(IntPtr hDROP, ref POINT lpPoint);
Esempio n. 16
0
 [DllImport("user32.dll")]//在桌面找寻子窗口
 public static extern IntPtr ChildWindowFromPointEx(IntPtr pHwnd, POINT pt, uint uFlgs);
Esempio n. 17
0
 public static extern int GetCursorPos(ref POINT lpPoint);
Esempio n. 18
0
 public static extern int GetCursorPos(out POINT lpPoint);
Esempio n. 19
0
 public static extern int PolyBezier(HDC hdc, ref POINT lppt, int cPoints);
Esempio n. 20
0
 public static extern int MenuItemFromPoint(HWND hwnd, HANDLE hMenu, POINT ptScreen);
Esempio n. 21
0
 public static extern int PolyDraw(HDC hdc, ref POINT lppt, ref Byte lpbTypes, int cCount);
Esempio n. 22
0
 public static extern int LPtoDP(HDC hdc, ref POINT lpPoint, int nCount);
Esempio n. 23
0
 [DllImport("user32.dll")]//进行坐标转换
 public static extern bool ScreenToClient(IntPtr hWnd, out POINT lpPoint);
Esempio n. 24
0
 public static extern int PlgBlt(HWND hdcDest, ref POINT lpPoint, HWND hdcSrc, int nXSrc, int nYSrc, int nWidth, int nHeight, HANDLE hbmMask, int xMask, int yMask);
Esempio n. 25
0
 public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, ref POINT lParam);
Esempio n. 26
0
 public static extern int PolyBezierTo(HDC hdc, ref POINT lppt, int cCount);
Esempio n. 27
0
 public static extern int DragQueryPoint(HANDLE hDROP, ref POINT lpPoint);
Esempio n. 28
0
 public static extern int Polyline(HDC hdc, ref POINT lpPoint, int nCount);
Esempio n. 29
0
 public static extern int CreatePolyPolygonRgn(ref POINT lpPoint, ref int lpPolyCounts, int nCount, int nPolyFillMode);
Esempio n. 30
0
 public static extern int PolyPolygon(HDC hdc, ref POINT lpPoint, ref int lpPolyCounts, int nCount);
Esempio n. 31
0
 public static extern int FixBrushOrgEx(HWND hdc, int n1, int n2, ref POINT lpPoint);
Esempio n. 32
0
 public static extern int SetBrushOrgEx(HDC hdc, int nXOrg, int nYOrg, ref POINT lppt);
Esempio n. 33
0
 public static extern int GetBrushOrgEx(HWND hdc, ref POINT lpPoint);
Esempio n. 34
0
 public static extern int SetWindowOrgEx(HDC hdc, int nX, int nY, ref POINT lpPoint);
Esempio n. 35
0
 public static extern int GetCurrentPositionEx(HDC hdc, ref POINT lpPoint);
Esempio n. 36
0
 public static extern int ClientToScreen(HWND hwnd, ref POINT lpPoint);
Esempio n. 37
0
 public static extern int GetPath(HDC hdc, ref POINT lpPoint, Byte lpTypes, int nSize);
Esempio n. 38
0
 public static extern int GetCaretPos(ref POINT lpPoint);
Esempio n. 39
0
 public static extern int GetViewportOrgEx(HDC hdc, ref POINT lpPoint);
Esempio n. 40
0
 public static extern int MapWindowPoints(HWND hwndFrom, HWND hwndTo, POINT[] lppt, int cPoints);
Esempio n. 41
0
 public static extern int GetWindowOrgEx(HDC hdc, ref POINT lpPoint);
Esempio n. 42
0
 public static extern int ScreenToClient(HWND hwnd, ref POINT lpPoint);
Esempio n. 43
0
 [DllImport("shell32")] public static extern int DragQueryPoint(HANDLE hDROP, ref POINT lpPoint);