mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
[WIP] Attempt to refresh Taskbar SystemTary and Overflow Notification Window
Trying to get rid of any left over applications that DIsplayMagician had to kill the process of, so that the system tray is nice and tidy. Having some issues doing so.
This commit is contained in:
parent
4f64537d89
commit
2e52e3ceb1
@ -26,8 +26,8 @@ using System.Resources;
|
||||
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
|
||||
|
||||
// Version information
|
||||
[assembly: AssemblyVersion("2.2.0.224")]
|
||||
[assembly: AssemblyFileVersion("2.2.0.224")]
|
||||
[assembly: AssemblyVersion("2.2.0.236")]
|
||||
[assembly: AssemblyFileVersion("2.2.0.236")]
|
||||
[assembly: NeutralResourcesLanguageAttribute( "en" )]
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
|
@ -10,16 +10,26 @@ namespace DisplayMagicianShared
|
||||
{
|
||||
class Utils
|
||||
{
|
||||
public static bool IsWindows11()
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct RECT
|
||||
{
|
||||
var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
|
||||
|
||||
var currentBuildStr = (string)reg.GetValue("CurrentBuild");
|
||||
var currentBuild = int.Parse(currentBuildStr);
|
||||
|
||||
return currentBuild >= 22000;
|
||||
public int left;
|
||||
public int top;
|
||||
public int right;
|
||||
public int bottom;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum SendMessageTimeoutFlag : uint
|
||||
{
|
||||
SMTO_NORMAL = 0x0,
|
||||
SMTO_BLOCK = 0x1,
|
||||
SMTO_ABORTIFHUNG = 0x2,
|
||||
SMTO_NOTIMEOUTIFNOTHUNG = 0x8,
|
||||
SMTO_ERRORONEXIT = 0x20
|
||||
}
|
||||
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr FindWindow(string lpClassName, String lpWindowName);
|
||||
|
||||
@ -34,20 +44,30 @@ namespace DisplayMagicianShared
|
||||
|
||||
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern int SendMessage(IntPtr hWnd, uint wMsg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
|
||||
|
||||
[Flags]
|
||||
public enum SendMessageTimeoutFlag : uint
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
|
||||
|
||||
public static bool IsWindows11()
|
||||
{
|
||||
SMTO_NORMAL = 0x0,
|
||||
SMTO_BLOCK = 0x1,
|
||||
SMTO_ABORTIFHUNG = 0x2,
|
||||
SMTO_NOTIMEOUTIFNOTHUNG = 0x8,
|
||||
SMTO_ERRORONEXIT = 0x20
|
||||
var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
|
||||
|
||||
var currentBuildStr = (string)reg.GetValue("CurrentBuild");
|
||||
var currentBuild = int.Parse(currentBuildStr);
|
||||
|
||||
return currentBuild >= 22000;
|
||||
}
|
||||
|
||||
public const int NULL = 0;
|
||||
public const int HWND_BROADCAST = 0xffff;
|
||||
public const int WM_SETTINGCHANGE = 0x001a;
|
||||
public const int WM_MOUSEMOVE = 0x0200;
|
||||
public const int SPI_SETWORKAREA = 0x002F;
|
||||
public const int WM_USER_REFRESHTASKBAR = 0x05CA;
|
||||
public const int wParam_SHELLTRAY = 0x00000006;
|
||||
|
@ -500,5 +500,52 @@ namespace DisplayMagicianShared.Windows
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void RefreshTrayArea()
|
||||
{
|
||||
// Tell Windows to refresh the Main Screen Windows Taskbar
|
||||
// Find the "Shell_TrayWnd" window
|
||||
//IntPtr SystemTrayHWnd = Utils.FindWindow("ToolbarWindow32", "User Promoted Notification Area");
|
||||
//RefreshTrayArea(SystemTrayHWnd);
|
||||
|
||||
IntPtr systemTrayContainerHandle = Utils.FindWindow("Shell_TrayWnd", null);
|
||||
IntPtr systemTrayHandle = Utils.FindWindowEx(systemTrayContainerHandle, IntPtr.Zero, "TrayNotifyWnd", null);
|
||||
IntPtr sysPagerHandle = Utils.FindWindowEx(systemTrayHandle, IntPtr.Zero, "SysPager", null);
|
||||
IntPtr notificationAreaHandle = Utils.FindWindowEx(sysPagerHandle, IntPtr.Zero, "ToolbarWindow32", "Notification Area");
|
||||
if (notificationAreaHandle == IntPtr.Zero)
|
||||
{
|
||||
notificationAreaHandle = Utils.FindWindowEx(sysPagerHandle, IntPtr.Zero, "ToolbarWindow32", "User Promoted Notification Area");
|
||||
IntPtr notifyIconOverflowWindowHandle = Utils.FindWindow("NotifyIconOverflowWindow", null);
|
||||
IntPtr overflowNotificationAreaHandle = Utils.FindWindowEx(notifyIconOverflowWindowHandle, IntPtr.Zero, "ToolbarWindow32", "Overflow Notification Area");
|
||||
//Utils.SendNotifyMessage(overflowNotificationAreaHandle, Utils.WM_PAINT, (UIntPtr)Utils.NULL, "");
|
||||
//Utils.SendNotifyMessage(overflowNotificationAreaHandle, Utils.WM_MOUSEMOVE, (UIntPtr)Utils.NULL, "");
|
||||
RefreshTrayArea(overflowNotificationAreaHandle);
|
||||
notifyIconOverflowWindowHandle = IntPtr.Zero;
|
||||
overflowNotificationAreaHandle = IntPtr.Zero;
|
||||
}
|
||||
RefreshTrayArea(notificationAreaHandle);
|
||||
systemTrayContainerHandle = IntPtr.Zero;
|
||||
systemTrayHandle = IntPtr.Zero;
|
||||
sysPagerHandle = IntPtr.Zero;
|
||||
notificationAreaHandle = IntPtr.Zero;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void RefreshTrayArea(IntPtr windowHandle)
|
||||
{
|
||||
// WM_CHANGEUISTATE wParam 0000000000010001, lParam 0000000000000000
|
||||
// WM_PAINT wParam 0000000000000000, lParam 0000000000000000
|
||||
// WM_NCPAINT wParam 0000000000000001, lParam 0000000000000000
|
||||
// WM_SETREDRAW wParam 0000000000000001, lParam 0000000000000000 (true)
|
||||
// WM_CHILDACTIVATE wParam 0000000000000000, lParam 0000000000000000
|
||||
|
||||
Utils.RECT rect;
|
||||
Utils.GetWindowRect(windowHandle, out rect);
|
||||
for (var x = rect.left; x < rect.right; x += 10)
|
||||
for (var y = rect.top; y < rect.bottom; y += 10)
|
||||
Utils.SendMessage(windowHandle, Utils.WM_MOUSEMOVE, 0, (y << 16) + x);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1439,12 +1439,8 @@ namespace DisplayMagicianShared.Windows
|
||||
SharedLogger.logger.Trace($"WinLibrary/SetActiveConfig: The current taskbar settings are the same as the one's we want, so skipping setting them!");
|
||||
}
|
||||
|
||||
// Restart Windows Explorer if we are in Win11 and if we need to make any TaskBar changes
|
||||
// If we get here, then we need to restart Windows Explorer for the taskbar registry changes to take effect!
|
||||
/*if (needToRestartExplorer && Utils.IsWindows11())
|
||||
{
|
||||
RestartExplorer();
|
||||
}*/
|
||||
// Lastly refesh the System Tray area so that any stopped programs disappear
|
||||
TaskBarStuckRectangle.RefreshTrayArea();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user