fixed #473
This commit is contained in:
1 parent
d1f6b5f7a0
commit
b30c6ff440
1 file changed
+29
-31
@@ -351,16 +351,15 @@ namespace HandyControl.Controls
|
||||
|
||||
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 @@ namespace HandyControl.Controls
|
||||
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 @@ namespace HandyControl.Controls
|
||||
return hWnd;
|
||||
}
|
||||
|
||||
private bool FindNotifyIcon(out InteropValues.RECT rect)
|
||||
private bool FindNotifyIcon(out List<InteropValues.RECT> rectList)
|
||||
{
|
||||
var rectNotify = new InteropValues.RECT();
|
||||
var rectNotifyList = new List<InteropValues.RECT>();
|
||||
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<InteropValues.RECT> rectNotifyList)
|
||||
{
|
||||
InteropMethods.GetWindowRect(hTrayWnd, out var rectTray);
|
||||
var count = (int)InteropMethods.SendMessage(hTrayWnd, InteropValues.TB_BUTTONCOUNT, 0, IntPtr.Zero);
|
||||
@@ -449,23 +447,27 @@ namespace HandyControl.Controls
|
||||
|
||||
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 @@ namespace HandyControl.Controls
|
||||
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 @@ namespace HandyControl.Controls
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user