diff --git a/VERSION b/VERSION index 3eefcb9..90a27f9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +1.0.5 diff --git a/bootstrap/payload/NativeMethods.cs b/bootstrap/payload/NativeMethods.cs index a5f2aac..41a415b 100644 --- a/bootstrap/payload/NativeMethods.cs +++ b/bootstrap/payload/NativeMethods.cs @@ -57,6 +57,8 @@ internal static class NativeMethods public const uint ABM_GETSTATE = 0x00000004; public const uint ABM_SETSTATE = 0x0000000A; public const uint ABS_AUTOHIDE = 0x0000001; + public const int GWL_STYLE = -16; + public const long WS_MAXIMIZE = 0x01000000L; [StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; } [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; public int Top; public int Right; public int Bottom; } @@ -95,8 +97,11 @@ internal static class NativeMethods [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childAfter, string className, string windowName); [DllImport("user32.dll")] public static extern bool IsWindow(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd); + [DllImport("user32.dll")] public static extern bool IsZoomed(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll", SetLastError = true)] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr insertAfter, int x, int y, int cx, int cy, uint flags); + [DllImport("user32.dll", EntryPoint = "GetWindowLongPtrW", SetLastError = true)] public static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex); + [DllImport("user32.dll", EntryPoint = "SetWindowLongPtrW", SetLastError = true)] public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr newLong); [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect); [DllImport("user32.dll")] public static extern IntPtr MonitorFromWindow(IntPtr hWnd, uint flags); [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO info); diff --git a/bootstrap/payload/SlipperyContext.Diagnostics.cs b/bootstrap/payload/SlipperyContext.Diagnostics.cs index 1081993..b36d747 100644 --- a/bootstrap/payload/SlipperyContext.Diagnostics.cs +++ b/bootstrap/payload/SlipperyContext.Diagnostics.cs @@ -20,7 +20,7 @@ private void CopyDiagnostics() { StringBuilder b = new StringBuilder(); b.AppendLine("Slippery Taskbar C# diagnostics"); - b.AppendLine("Build: 1.0.0"); + b.AppendLine("Build: 1.0.5-force-maximized"); b.AppendLine("Runtime: " + Environment.Version); b.AppendLine("OS: " + Environment.OSVersion); b.AppendLine("Executable: " + Application.ExecutablePath); @@ -29,6 +29,8 @@ private void CopyDiagnostics() b.AppendLine("Start with Windows: " + _startWithWindows); b.AppendLine("Keep visible while interacting: " + _preferencesStore.Current.KeepVisibleWhileInteracting); b.AppendLine("Native auto-hide active: " + ((_taskbars.GetAppbarState() & NativeMethods.ABS_AUTOHIDE) != 0)); + b.AppendLine("Forced maximized windows last pass: " + _taskbars.LastForcedMaximizedCount); + b.AppendLine("Forced maximized windows total: " + _taskbars.TotalForcedMaximizedCount); b.AppendLine("Tray visibility guard active: " + (DateTime.UtcNow < _trayInteractionPinUntilUtc || _taskbars.IsTrayOverflowOpen())); b.AppendLine("Notification-area mouse guard installed: " + (_mouseHook != IntPtr.Zero)); b.AppendLine("Work area: " + _taskbars.DescribeWorkArea()); diff --git a/bootstrap/payload/SlipperyContext.Polling.cs b/bootstrap/payload/SlipperyContext.Polling.cs index 02a80e3..7fa90f6 100644 --- a/bootstrap/payload/SlipperyContext.Polling.cs +++ b/bootstrap/payload/SlipperyContext.Polling.cs @@ -28,11 +28,6 @@ private IntPtr MouseHookCallback(int nCode, IntPtr wParam, IntPtr lParam) NativeMethods.MSLLHOOKSTRUCT mouse = (NativeMethods.MSLLHOOKSTRUCT)Marshal.PtrToStructure( lParam, typeof(NativeMethods.MSLLHOOKSTRUCT)); - // Do not touch ABM_SETSTATE here. Changing ABS_AUTOHIDE causes - // Explorer to recalculate the desktop work area, which makes - // maximized windows resize when Win or a tray flyout is used. - // Instead, pre-authorize the notification-area transition and - // keep the actual taskbar window physically on-screen. if (_taskbars.IsPointOverNotificationArea(mouse.pt)) { TimeSpan grace = message == NativeMethods.WM_LBUTTONDOWN @@ -79,21 +74,13 @@ private void PollTaskbarState() bool shouldShow = _winDown || shellUi || interacting || trayVisibilityGuard || now < _visibleUntilUtc; + if (!shouldShow) + _taskbars.ForceAllMaximizedWindowsIntoTopAndSideGaps(); + bool anyTaskbarVisible; bool allTaskbarsVisible; _taskbars.GetActualVisibilityState(out anyTaskbarVisible, out allTaskbarsVisible); - // Native auto-hide is enabled only so Windows releases the taskbar's work - // area. Explorer may still try to reveal the bar when the pointer touches - // an edge, so immediately correct any visibility that Slippery did not - // authorize. Conversely, if Explorer auto-hides while Start/shell UI is - // active, put the taskbar back on-screen. - // Only correct the dangerous direction here: Explorer revealing a - // taskbar that Slippery intends to keep hidden. When the taskbar is - // intentionally visible, Explorer is allowed to own the intermediate - // frames of Start/tray/XAML animations. Re-showing or repositioning the - // taskbar during those frames is what caused the visible close/reopen - // stutter around the hidden-icons flyout. bool unauthorizedReveal = !shouldShow && anyTaskbarVisible; if (shouldShow != _lastShouldShow || unauthorizedReveal || _lastApplyUtc == DateTime.MinValue) diff --git a/bootstrap/payload/TaskbarController.Core.cs b/bootstrap/payload/TaskbarController.Core.cs index 21a84fe..89b37e0 100644 --- a/bootstrap/payload/TaskbarController.Core.cs +++ b/bootstrap/payload/TaskbarController.Core.cs @@ -22,6 +22,9 @@ internal sealed partial class TaskbarController private bool _originalAppbarCaptured; private readonly List _originalWorkAreas = new List(); private bool _workAreasCaptured; + private DateTime _lastForcedMaximizedPassUtc = DateTime.MinValue; + private int _lastForcedMaximizedCount; + private int _totalForcedMaximizedCount; private sealed class WorkAreaEntry { @@ -73,15 +76,98 @@ public void ApplyVisibility(bool show) { if (!NativeMethods.IsWindow(h)) continue; - // Match Buttery Taskbar's least-invasive visibility model: one - // synchronous ShowWindow call, with Explorer left in control of the - // taskbar's own auto-hide/XAML animation and position. Do not pair - // this with SetWindowPos or force the bar back onto the monitor; those - // operations can fight Explorer mid-animation and create a flash. NativeMethods.ShowWindow(h, show ? NativeMethods.SW_SHOWNOACTIVATE : NativeMethods.SW_HIDE); } } + public void ForceAllMaximizedWindowsIntoTopAndSideGaps() + { + DateTime now = DateTime.UtcNow; + if (_lastForcedMaximizedPassUtc != DateTime.MinValue && + now - _lastForcedMaximizedPassUtc < TimeSpan.FromMilliseconds(90)) + return; + _lastForcedMaximizedPassUtc = now; + _lastForcedMaximizedCount = 0; + + NativeMethods.EnumWindows(delegate(IntPtr hWnd, IntPtr lParam) + { + if (!NativeMethods.IsWindow(hWnd) || !NativeMethods.IsWindowVisible(hWnd)) return true; + if (!NativeMethods.IsZoomed(hWnd)) return true; + + string cls = GetWindowClass(hWnd); + if (IsTaskbarClass(cls) || IsShellUiWindow(hWnd)) return true; + + IntPtr monitor = NativeMethods.MonitorFromWindow(hWnd, NativeMethods.MONITOR_DEFAULTTONEAREST); + if (monitor == IntPtr.Zero) return true; + + NativeMethods.MONITORINFO mi = new NativeMethods.MONITORINFO(); + mi.cbSize = Marshal.SizeOf(typeof(NativeMethods.MONITORINFO)); + if (!NativeMethods.GetMonitorInfo(monitor, ref mi)) return true; + + int topReserve = mi.rcWork.Top - mi.rcMonitor.Top; + int leftReserve = mi.rcWork.Left - mi.rcMonitor.Left; + int rightReserve = mi.rcMonitor.Right - mi.rcWork.Right; + + if (topReserve < 8 && leftReserve < 8 && rightReserve < 8) return true; + + NativeMethods.RECT r; + if (!NativeMethods.GetWindowRect(hWnd, out r)) return true; + + int tolerance = 40; + bool looksLikeWorkAreaMaximized = + r.Left <= mi.rcWork.Left + tolerance && + r.Top <= mi.rcWork.Top + tolerance && + r.Right >= mi.rcWork.Right - tolerance && + r.Bottom >= mi.rcWork.Bottom - tolerance; + if (!looksLikeWorkAreaMaximized) return true; + + IntPtr stylePtr = NativeMethods.GetWindowLongPtr(hWnd, NativeMethods.GWL_STYLE); + long style = stylePtr.ToInt64(); + if ((style & NativeMethods.WS_MAXIMIZE) == 0) return true; + + int extraLeft = Math.Max(0, mi.rcWork.Left - r.Left); + int extraTop = Math.Max(0, mi.rcWork.Top - r.Top); + int extraRight = Math.Max(0, r.Right - mi.rcWork.Right); + int extraBottom = Math.Max(0, r.Bottom - mi.rcWork.Bottom); + + int x = mi.rcMonitor.Left - extraLeft; + int y = mi.rcMonitor.Top - extraTop; + int right = mi.rcMonitor.Right + extraRight; + int bottom = mi.rcMonitor.Bottom + extraBottom; + int cx = right - x; + int cy = bottom - y; + if (cx <= 0 || cy <= 0) return true; + + IntPtr restoredStyle = new IntPtr(style & ~NativeMethods.WS_MAXIMIZE); + IntPtr previousStyle = NativeMethods.SetWindowLongPtr(hWnd, NativeMethods.GWL_STYLE, restoredStyle); + bool clearedMaximizeStyle = previousStyle != IntPtr.Zero; + + bool moved = NativeMethods.SetWindowPos(hWnd, IntPtr.Zero, x, y, cx, cy, + NativeMethods.SWP_NOACTIVATE | NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOSENDCHANGING); + + if (clearedMaximizeStyle) + NativeMethods.SetWindowLongPtr(hWnd, NativeMethods.GWL_STYLE, stylePtr); + + if (moved) + { + _lastForcedMaximizedCount++; + _totalForcedMaximizedCount++; + } + + return true; + }, IntPtr.Zero); + } + + public int LastForcedMaximizedCount + { + get { return _lastForcedMaximizedCount; } + } + + public int TotalForcedMaximizedCount + { + get { return _totalForcedMaximizedCount; } + } + private static void ForceTaskbarOnScreen(IntPtr h) { NativeMethods.RECT r; @@ -131,8 +217,12 @@ public uint GetAppbarState() private void SetAppbarState(uint state) { + IntPtr primaryTaskbar = NativeMethods.FindWindow("Shell_TrayWnd", null); + if (primaryTaskbar == IntPtr.Zero) return; + NativeMethods.APPBARDATA data = new NativeMethods.APPBARDATA(); data.cbSize = (uint)Marshal.SizeOf(typeof(NativeMethods.APPBARDATA)); + data.hWnd = primaryTaskbar; data.lParam = new IntPtr((long)state); NativeMethods.SHAppBarMessage(NativeMethods.ABM_SETSTATE, ref data); } diff --git a/src/NativeMethods.cs b/src/NativeMethods.cs index a5f2aac..41a415b 100644 --- a/src/NativeMethods.cs +++ b/src/NativeMethods.cs @@ -57,6 +57,8 @@ internal static class NativeMethods public const uint ABM_GETSTATE = 0x00000004; public const uint ABM_SETSTATE = 0x0000000A; public const uint ABS_AUTOHIDE = 0x0000001; + public const int GWL_STYLE = -16; + public const long WS_MAXIMIZE = 0x01000000L; [StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; } [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; public int Top; public int Right; public int Bottom; } @@ -95,8 +97,11 @@ internal static class NativeMethods [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childAfter, string className, string windowName); [DllImport("user32.dll")] public static extern bool IsWindow(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd); + [DllImport("user32.dll")] public static extern bool IsZoomed(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll", SetLastError = true)] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr insertAfter, int x, int y, int cx, int cy, uint flags); + [DllImport("user32.dll", EntryPoint = "GetWindowLongPtrW", SetLastError = true)] public static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex); + [DllImport("user32.dll", EntryPoint = "SetWindowLongPtrW", SetLastError = true)] public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr newLong); [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect); [DllImport("user32.dll")] public static extern IntPtr MonitorFromWindow(IntPtr hWnd, uint flags); [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO info); diff --git a/src/SlipperyContext.Diagnostics.cs b/src/SlipperyContext.Diagnostics.cs index 1081993..b36d747 100644 --- a/src/SlipperyContext.Diagnostics.cs +++ b/src/SlipperyContext.Diagnostics.cs @@ -20,7 +20,7 @@ private void CopyDiagnostics() { StringBuilder b = new StringBuilder(); b.AppendLine("Slippery Taskbar C# diagnostics"); - b.AppendLine("Build: 1.0.0"); + b.AppendLine("Build: 1.0.5-force-maximized"); b.AppendLine("Runtime: " + Environment.Version); b.AppendLine("OS: " + Environment.OSVersion); b.AppendLine("Executable: " + Application.ExecutablePath); @@ -29,6 +29,8 @@ private void CopyDiagnostics() b.AppendLine("Start with Windows: " + _startWithWindows); b.AppendLine("Keep visible while interacting: " + _preferencesStore.Current.KeepVisibleWhileInteracting); b.AppendLine("Native auto-hide active: " + ((_taskbars.GetAppbarState() & NativeMethods.ABS_AUTOHIDE) != 0)); + b.AppendLine("Forced maximized windows last pass: " + _taskbars.LastForcedMaximizedCount); + b.AppendLine("Forced maximized windows total: " + _taskbars.TotalForcedMaximizedCount); b.AppendLine("Tray visibility guard active: " + (DateTime.UtcNow < _trayInteractionPinUntilUtc || _taskbars.IsTrayOverflowOpen())); b.AppendLine("Notification-area mouse guard installed: " + (_mouseHook != IntPtr.Zero)); b.AppendLine("Work area: " + _taskbars.DescribeWorkArea()); diff --git a/src/SlipperyContext.Polling.cs b/src/SlipperyContext.Polling.cs index 02a80e3..fc1247b 100644 --- a/src/SlipperyContext.Polling.cs +++ b/src/SlipperyContext.Polling.cs @@ -28,11 +28,6 @@ private IntPtr MouseHookCallback(int nCode, IntPtr wParam, IntPtr lParam) NativeMethods.MSLLHOOKSTRUCT mouse = (NativeMethods.MSLLHOOKSTRUCT)Marshal.PtrToStructure( lParam, typeof(NativeMethods.MSLLHOOKSTRUCT)); - // Do not touch ABM_SETSTATE here. Changing ABS_AUTOHIDE causes - // Explorer to recalculate the desktop work area, which makes - // maximized windows resize when Win or a tray flyout is used. - // Instead, pre-authorize the notification-area transition and - // keep the actual taskbar window physically on-screen. if (_taskbars.IsPointOverNotificationArea(mouse.pt)) { TimeSpan grace = message == NativeMethods.WM_LBUTTONDOWN @@ -79,21 +74,18 @@ private void PollTaskbarState() bool shouldShow = _winDown || shellUi || interacting || trayVisibilityGuard || now < _visibleUntilUtc; + // On top/left/right layouts some Explorer variants keep a real work-area + // reservation even though Slippery hides the taskbar. Standard maximized + // windows then refuse a normal SetWindowPos and snap back to rcWork. + // While hidden, force every visible maximized window to the full monitor + // by temporarily clearing WS_MAXIMIZE during the move, then restoring it. + if (!shouldShow) + _taskbars.ForceAllMaximizedWindowsIntoTopAndSideGaps(); + bool anyTaskbarVisible; bool allTaskbarsVisible; _taskbars.GetActualVisibilityState(out anyTaskbarVisible, out allTaskbarsVisible); - // Native auto-hide is enabled only so Windows releases the taskbar's work - // area. Explorer may still try to reveal the bar when the pointer touches - // an edge, so immediately correct any visibility that Slippery did not - // authorize. Conversely, if Explorer auto-hides while Start/shell UI is - // active, put the taskbar back on-screen. - // Only correct the dangerous direction here: Explorer revealing a - // taskbar that Slippery intends to keep hidden. When the taskbar is - // intentionally visible, Explorer is allowed to own the intermediate - // frames of Start/tray/XAML animations. Re-showing or repositioning the - // taskbar during those frames is what caused the visible close/reopen - // stutter around the hidden-icons flyout. bool unauthorizedReveal = !shouldShow && anyTaskbarVisible; if (shouldShow != _lastShouldShow || unauthorizedReveal || _lastApplyUtc == DateTime.MinValue) diff --git a/src/SlipperyTaskbar.csproj b/src/SlipperyTaskbar.csproj index 7df1bfa..5ba8c65 100644 --- a/src/SlipperyTaskbar.csproj +++ b/src/SlipperyTaskbar.csproj @@ -13,8 +13,8 @@ true true false - 1.0.0 - 1.0.0.0 + 1.0.5 + 1.0.5.0 Slippery Taskbar Hide the Windows 11 taskbar until the Windows key or shell UI intentionally reveals it. diff --git a/src/TaskbarController.Core.cs b/src/TaskbarController.Core.cs index 21a84fe..3f51655 100644 --- a/src/TaskbarController.Core.cs +++ b/src/TaskbarController.Core.cs @@ -22,6 +22,9 @@ internal sealed partial class TaskbarController private bool _originalAppbarCaptured; private readonly List _originalWorkAreas = new List(); private bool _workAreasCaptured; + private DateTime _lastForcedMaximizedPassUtc = DateTime.MinValue; + private int _lastForcedMaximizedCount; + private int _totalForcedMaximizedCount; private sealed class WorkAreaEntry { @@ -73,15 +76,100 @@ public void ApplyVisibility(bool show) { if (!NativeMethods.IsWindow(h)) continue; - // Match Buttery Taskbar's least-invasive visibility model: one - // synchronous ShowWindow call, with Explorer left in control of the - // taskbar's own auto-hide/XAML animation and position. Do not pair - // this with SetWindowPos or force the bar back onto the monitor; those - // operations can fight Explorer mid-animation and create a flash. NativeMethods.ShowWindow(h, show ? NativeMethods.SW_SHOWNOACTIVATE : NativeMethods.SW_HIDE); } } + public void ForceAllMaximizedWindowsIntoTopAndSideGaps() + { + DateTime now = DateTime.UtcNow; + if (_lastForcedMaximizedPassUtc != DateTime.MinValue && + now - _lastForcedMaximizedPassUtc < TimeSpan.FromMilliseconds(90)) + return; + _lastForcedMaximizedPassUtc = now; + _lastForcedMaximizedCount = 0; + + NativeMethods.EnumWindows(delegate(IntPtr hWnd, IntPtr lParam) + { + if (!NativeMethods.IsWindow(hWnd) || !NativeMethods.IsWindowVisible(hWnd)) return true; + if (!NativeMethods.IsZoomed(hWnd)) return true; + + string cls = GetWindowClass(hWnd); + if (IsTaskbarClass(cls) || IsShellUiWindow(hWnd)) return true; + + IntPtr monitor = NativeMethods.MonitorFromWindow(hWnd, NativeMethods.MONITOR_DEFAULTTONEAREST); + if (monitor == IntPtr.Zero) return true; + + NativeMethods.MONITORINFO mi = new NativeMethods.MONITORINFO(); + mi.cbSize = Marshal.SizeOf(typeof(NativeMethods.MONITORINFO)); + if (!NativeMethods.GetMonitorInfo(monitor, ref mi)) return true; + + int topReserve = mi.rcWork.Top - mi.rcMonitor.Top; + int leftReserve = mi.rcWork.Left - mi.rcMonitor.Left; + int rightReserve = mi.rcMonitor.Right - mi.rcWork.Right; + + // Bottom placement already behaves correctly. Only force windows when + // Windows is still reserving a meaningful strip on the top/left/right. + if (topReserve < 8 && leftReserve < 8 && rightReserve < 8) return true; + + NativeMethods.RECT r; + if (!NativeMethods.GetWindowRect(hWnd, out r)) return true; + + int tolerance = 40; + bool looksLikeWorkAreaMaximized = + r.Left <= mi.rcWork.Left + tolerance && + r.Top <= mi.rcWork.Top + tolerance && + r.Right >= mi.rcWork.Right - tolerance && + r.Bottom >= mi.rcWork.Bottom - tolerance; + if (!looksLikeWorkAreaMaximized) return true; + + IntPtr stylePtr = NativeMethods.GetWindowLongPtr(hWnd, NativeMethods.GWL_STYLE); + long style = stylePtr.ToInt64(); + if ((style & NativeMethods.WS_MAXIMIZE) == 0) return true; + + int extraLeft = Math.Max(0, mi.rcWork.Left - r.Left); + int extraTop = Math.Max(0, mi.rcWork.Top - r.Top); + int extraRight = Math.Max(0, r.Right - mi.rcWork.Right); + int extraBottom = Math.Max(0, r.Bottom - mi.rcWork.Bottom); + + int x = mi.rcMonitor.Left - extraLeft; + int y = mi.rcMonitor.Top - extraTop; + int right = mi.rcMonitor.Right + extraRight; + int bottom = mi.rcMonitor.Bottom + extraBottom; + int cx = right - x; + int cy = bottom - y; + if (cx <= 0 || cy <= 0) return true; + + IntPtr restoredStyle = new IntPtr(style & ~NativeMethods.WS_MAXIMIZE); + IntPtr previousStyle = NativeMethods.SetWindowLongPtr(hWnd, NativeMethods.GWL_STYLE, restoredStyle); + bool clearedMaximizeStyle = previousStyle != IntPtr.Zero; + + bool moved = NativeMethods.SetWindowPos(hWnd, IntPtr.Zero, x, y, cx, cy, + NativeMethods.SWP_NOACTIVATE | NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOSENDCHANGING); + + if (clearedMaximizeStyle) + NativeMethods.SetWindowLongPtr(hWnd, NativeMethods.GWL_STYLE, stylePtr); + + if (moved) + { + _lastForcedMaximizedCount++; + _totalForcedMaximizedCount++; + } + + return true; + }, IntPtr.Zero); + } + + public int LastForcedMaximizedCount + { + get { return _lastForcedMaximizedCount; } + } + + public int TotalForcedMaximizedCount + { + get { return _totalForcedMaximizedCount; } + } + private static void ForceTaskbarOnScreen(IntPtr h) { NativeMethods.RECT r; @@ -131,8 +219,12 @@ public uint GetAppbarState() private void SetAppbarState(uint state) { + IntPtr primaryTaskbar = NativeMethods.FindWindow("Shell_TrayWnd", null); + if (primaryTaskbar == IntPtr.Zero) return; + NativeMethods.APPBARDATA data = new NativeMethods.APPBARDATA(); data.cbSize = (uint)Marshal.SizeOf(typeof(NativeMethods.APPBARDATA)); + data.hWnd = primaryTaskbar; data.lParam = new IntPtr((long)state); NativeMethods.SHAppBarMessage(NativeMethods.ABM_SETSTATE, ref data); }