diff --git a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs index f62170575..8b55c3436 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs @@ -351,16 +351,15 @@ private void DispatcherTimerBlinkTick(object sender, EventArgs e) private bool CheckMouseIsEnter() { - var isTrue = FindNotifyIcon(out var rectNotify); + var isTrue = FindNotifyIcon(out var rectNotifyList); if (!isTrue) return false; - InteropMethods.GetCursorPos(out var point); - if (point.X >= rectNotify.Left && point.X <= rectNotify.Right && - point.Y >= rectNotify.Top && point.Y <= rectNotify.Bottom) - { - return true; - } - return false; + InteropMethods.GetCursorPos(out var point); + return rectNotifyList.Any(rectNotify => + point.X >= rectNotify.Left && + point.X <= rectNotify.Right && + point.Y >= rectNotify.Top && + point.Y <= rectNotify.Bottom); } private void DispatcherTimerPos_Tick(object sender, EventArgs e) @@ -397,15 +396,14 @@ private IntPtr FindTrayToolbarWindow() hWnd = InteropMethods.FindWindowEx(hWnd, IntPtr.Zero, "TrayNotifyWnd", null); if (hWnd != IntPtr.Zero) { - hWnd = InteropMethods.FindWindowEx(hWnd, IntPtr.Zero, "SysPager", null); if (hWnd != IntPtr.Zero) { hWnd = InteropMethods.FindWindowEx(hWnd, IntPtr.Zero, "ToolbarWindow32", null); - } } } + return hWnd; } @@ -420,22 +418,22 @@ private IntPtr FindTrayToolbarOverFlowWindow() return hWnd; } - private bool FindNotifyIcon(out InteropValues.RECT rect) + private bool FindNotifyIcon(out List rectList) { - var rectNotify = new InteropValues.RECT(); + var rectNotifyList = new List(); var hTrayWnd = FindTrayToolbarWindow(); - var isTrue = FindNotifyIcon(hTrayWnd, ref rectNotify); + var isTrue = FindNotifyIcon(hTrayWnd, ref rectNotifyList); if (!isTrue) { hTrayWnd = FindTrayToolbarOverFlowWindow(); - isTrue = FindNotifyIcon(hTrayWnd, ref rectNotify); + isTrue = FindNotifyIcon(hTrayWnd, ref rectNotifyList); } - rect = rectNotify; + rectList = rectNotifyList; return isTrue; } //referenced from http://www.cnblogs.com/sczmzx/p/5158127.html - private bool FindNotifyIcon(IntPtr hTrayWnd, ref InteropValues.RECT rectNotify) + private bool FindNotifyIcon(IntPtr hTrayWnd, ref List rectNotifyList) { InteropMethods.GetWindowRect(hTrayWnd, out var rectTray); var count = (int)InteropMethods.SendMessage(hTrayWnd, InteropValues.TB_BUTTONCOUNT, 0, IntPtr.Zero); @@ -449,23 +447,27 @@ private bool FindNotifyIcon(IntPtr hTrayWnd, ref InteropValues.RECT rectNotify) var btnData = new InteropValues.TBBUTTON(); var trayData = new InteropValues.TRAYDATA(); - var handel = Process.GetCurrentProcess().Id; + var handle = Process.GetCurrentProcess().Id; for (uint i = 0; i < count; i++) { InteropMethods.SendMessage(hTrayWnd, InteropValues.TB_GETBUTTON, i, address); var isTrue = InteropMethods.ReadProcessMemory(hProcess, address, out btnData, Marshal.SizeOf(btnData), out _); if (!isTrue) continue; + if (btnData.dwData == IntPtr.Zero) { btnData.dwData = btnData.iString; } + InteropMethods.ReadProcessMemory(hProcess, btnData.dwData, out trayData, Marshal.SizeOf(trayData), out _); InteropMethods.GetWindowThreadProcessId(trayData.hwnd, out var dwProcessId); - if (dwProcessId == (uint)handel) + + if (dwProcessId == (uint)handle) { var rect = new InteropValues.RECT(); var lngRect = InteropMethods.VirtualAllocEx(hProcess, IntPtr.Zero, Marshal.SizeOf(typeof(Rect)), InteropValues.AllocationType.Commit, InteropValues.MemoryProtection.ReadWrite); + InteropMethods.SendMessage(hTrayWnd, InteropValues.TB_GETITEMRECT, i, lngRect); InteropMethods.ReadProcessMemory(hProcess, lngRect, out rect, Marshal.SizeOf(rect), out _); @@ -476,15 +478,14 @@ private bool FindNotifyIcon(IntPtr hTrayWnd, ref InteropValues.RECT rectNotify) var top = rectTray.Top + rect.Top; var botton = rectTray.Top + rect.Bottom; var right = rectTray.Left + rect.Right; - rectNotify = new InteropValues.RECT + rectNotifyList.Add(new InteropValues.RECT { Left = left, Right = right, Top = top, Bottom = botton - }; + }); isFind = true; - break; } } InteropMethods.VirtualFreeEx(hProcess, address, 0x4096, InteropValues.FreeType.Decommit); @@ -641,17 +642,14 @@ private void ShowContextMenu() if (ContextContent != null) { - if (_contextContent == null) + _contextContent ??= new Popup { - _contextContent = new Popup - { - Placement = PlacementMode.Mouse, - AllowsTransparency = true, - StaysOpen = false, - UseLayoutRounding = true, - SnapsToDevicePixels = true - }; - } + Placement = PlacementMode.Mouse, + AllowsTransparency = true, + StaysOpen = false, + UseLayoutRounding = true, + SnapsToDevicePixels = true + }; _contextContent.Child = new ContentControl {