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()
|
private bool CheckMouseIsEnter()
|
||||||
{
|
{
|
||||||
var isTrue = FindNotifyIcon(out var rectNotify);
|
var isTrue = FindNotifyIcon(out var rectNotifyList);
|
||||||
if (!isTrue) return false;
|
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)
|
private void DispatcherTimerPos_Tick(object sender, EventArgs e)
|
||||||
@@ -397,15 +396,14 @@ namespace HandyControl.Controls
|
|||||||
hWnd = InteropMethods.FindWindowEx(hWnd, IntPtr.Zero, "TrayNotifyWnd", null);
|
hWnd = InteropMethods.FindWindowEx(hWnd, IntPtr.Zero, "TrayNotifyWnd", null);
|
||||||
if (hWnd != IntPtr.Zero)
|
if (hWnd != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
|
|
||||||
hWnd = InteropMethods.FindWindowEx(hWnd, IntPtr.Zero, "SysPager", null);
|
hWnd = InteropMethods.FindWindowEx(hWnd, IntPtr.Zero, "SysPager", null);
|
||||||
if (hWnd != IntPtr.Zero)
|
if (hWnd != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
hWnd = InteropMethods.FindWindowEx(hWnd, IntPtr.Zero, "ToolbarWindow32", null);
|
hWnd = InteropMethods.FindWindowEx(hWnd, IntPtr.Zero, "ToolbarWindow32", null);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return hWnd;
|
return hWnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,22 +418,22 @@ namespace HandyControl.Controls
|
|||||||
return hWnd;
|
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 hTrayWnd = FindTrayToolbarWindow();
|
||||||
var isTrue = FindNotifyIcon(hTrayWnd, ref rectNotify);
|
var isTrue = FindNotifyIcon(hTrayWnd, ref rectNotifyList);
|
||||||
if (!isTrue)
|
if (!isTrue)
|
||||||
{
|
{
|
||||||
hTrayWnd = FindTrayToolbarOverFlowWindow();
|
hTrayWnd = FindTrayToolbarOverFlowWindow();
|
||||||
isTrue = FindNotifyIcon(hTrayWnd, ref rectNotify);
|
isTrue = FindNotifyIcon(hTrayWnd, ref rectNotifyList);
|
||||||
}
|
}
|
||||||
rect = rectNotify;
|
rectList = rectNotifyList;
|
||||||
return isTrue;
|
return isTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//referenced from http://www.cnblogs.com/sczmzx/p/5158127.html
|
//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);
|
InteropMethods.GetWindowRect(hTrayWnd, out var rectTray);
|
||||||
var count = (int)InteropMethods.SendMessage(hTrayWnd, InteropValues.TB_BUTTONCOUNT, 0, IntPtr.Zero);
|
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 btnData = new InteropValues.TBBUTTON();
|
||||||
var trayData = new InteropValues.TRAYDATA();
|
var trayData = new InteropValues.TRAYDATA();
|
||||||
var handel = Process.GetCurrentProcess().Id;
|
var handle = Process.GetCurrentProcess().Id;
|
||||||
|
|
||||||
for (uint i = 0; i < count; i++)
|
for (uint i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
InteropMethods.SendMessage(hTrayWnd, InteropValues.TB_GETBUTTON, i, address);
|
InteropMethods.SendMessage(hTrayWnd, InteropValues.TB_GETBUTTON, i, address);
|
||||||
var isTrue = InteropMethods.ReadProcessMemory(hProcess, address, out btnData, Marshal.SizeOf(btnData), out _);
|
var isTrue = InteropMethods.ReadProcessMemory(hProcess, address, out btnData, Marshal.SizeOf(btnData), out _);
|
||||||
if (!isTrue) continue;
|
if (!isTrue) continue;
|
||||||
|
|
||||||
if (btnData.dwData == IntPtr.Zero)
|
if (btnData.dwData == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
btnData.dwData = btnData.iString;
|
btnData.dwData = btnData.iString;
|
||||||
}
|
}
|
||||||
|
|
||||||
InteropMethods.ReadProcessMemory(hProcess, btnData.dwData, out trayData, Marshal.SizeOf(trayData), out _);
|
InteropMethods.ReadProcessMemory(hProcess, btnData.dwData, out trayData, Marshal.SizeOf(trayData), out _);
|
||||||
InteropMethods.GetWindowThreadProcessId(trayData.hwnd, out var dwProcessId);
|
InteropMethods.GetWindowThreadProcessId(trayData.hwnd, out var dwProcessId);
|
||||||
if (dwProcessId == (uint)handel)
|
|
||||||
|
if (dwProcessId == (uint)handle)
|
||||||
{
|
{
|
||||||
var rect = new InteropValues.RECT();
|
var rect = new InteropValues.RECT();
|
||||||
var lngRect = InteropMethods.VirtualAllocEx(hProcess, IntPtr.Zero, Marshal.SizeOf(typeof(Rect)), InteropValues.AllocationType.Commit, InteropValues.MemoryProtection.ReadWrite);
|
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.SendMessage(hTrayWnd, InteropValues.TB_GETITEMRECT, i, lngRect);
|
||||||
InteropMethods.ReadProcessMemory(hProcess, lngRect, out rect, Marshal.SizeOf(rect), out _);
|
InteropMethods.ReadProcessMemory(hProcess, lngRect, out rect, Marshal.SizeOf(rect), out _);
|
||||||
|
|
||||||
@@ -476,15 +478,14 @@ namespace HandyControl.Controls
|
|||||||
var top = rectTray.Top + rect.Top;
|
var top = rectTray.Top + rect.Top;
|
||||||
var botton = rectTray.Top + rect.Bottom;
|
var botton = rectTray.Top + rect.Bottom;
|
||||||
var right = rectTray.Left + rect.Right;
|
var right = rectTray.Left + rect.Right;
|
||||||
rectNotify = new InteropValues.RECT
|
rectNotifyList.Add(new InteropValues.RECT
|
||||||
{
|
{
|
||||||
Left = left,
|
Left = left,
|
||||||
Right = right,
|
Right = right,
|
||||||
Top = top,
|
Top = top,
|
||||||
Bottom = botton
|
Bottom = botton
|
||||||
};
|
});
|
||||||
isFind = true;
|
isFind = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InteropMethods.VirtualFreeEx(hProcess, address, 0x4096, InteropValues.FreeType.Decommit);
|
InteropMethods.VirtualFreeEx(hProcess, address, 0x4096, InteropValues.FreeType.Decommit);
|
||||||
@@ -641,17 +642,14 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
if (ContextContent != null)
|
if (ContextContent != null)
|
||||||
{
|
{
|
||||||
if (_contextContent == null)
|
_contextContent ??= new Popup
|
||||||
{
|
{
|
||||||
_contextContent = new Popup
|
Placement = PlacementMode.Mouse,
|
||||||
{
|
AllowsTransparency = true,
|
||||||
Placement = PlacementMode.Mouse,
|
StaysOpen = false,
|
||||||
AllowsTransparency = true,
|
UseLayoutRounding = true,
|
||||||
StaysOpen = false,
|
SnapsToDevicePixels = true
|
||||||
UseLayoutRounding = true,
|
};
|
||||||
SnapsToDevicePixels = true
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_contextContent.Child = new ContentControl
|
_contextContent.Child = new ContentControl
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user