From 919399c622aad9163df349bda8028bff407bfb4f Mon Sep 17 00:00:00 2001 From: charles7668 Date: Wed, 11 Sep 2024 14:55:18 +0800 Subject: [PATCH] Fix toggle taskbar hidden when window is maximized --- Tiefsee/Lib/WindowAPI.cs | 33 +++++++++++++++++++++++++++++++++ Tiefsee/VW/WV_Window.cs | 1 + Tiefsee/WebWindow.cs | 17 +++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/Tiefsee/Lib/WindowAPI.cs b/Tiefsee/Lib/WindowAPI.cs index c18b101..a4027be 100644 --- a/Tiefsee/Lib/WindowAPI.cs +++ b/Tiefsee/Lib/WindowAPI.cs @@ -286,6 +286,39 @@ public static void GlobalActivate(IntPtr interopHelper) { private static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach); #endregion + + #region 任務欄 + + [StructLayout(LayoutKind.Sequential)] + public struct APPBARDATA + { + public int cbSize; + public IntPtr hWnd; + public uint uCallbackMessage; + public uint uEdge; + public RECT rc; + public int lParam; + } + + [StructLayout(LayoutKind.Sequential)] + public struct RECT + { + public int left; + public int top; + public int right; + public int bottom; + } + + [DllImport("shell32.dll", SetLastError = true)] + public static extern uint SHAppBarMessage(uint dwMessage, ref APPBARDATA pData); + + // ABM_GETSTATE 用來檢查任務欄狀態的訊息 + public const uint ABM_GETSTATE = 0x00000004; + + // 設定任務欄的狀態,當值為 ABS_AUTOHIDE 時,表示啟用了自動隱藏 + public const int ABS_AUTOHIDE = 0x1; + + #endregion } } diff --git a/Tiefsee/VW/WV_Window.cs b/Tiefsee/VW/WV_Window.cs index 2c723f2..ad6ccff 100644 --- a/Tiefsee/VW/WV_Window.cs +++ b/Tiefsee/VW/WV_Window.cs @@ -350,6 +350,7 @@ public string WindowState { set { if (value == "Maximized") { // WebWindow.ShowWindow(M.Handle, WebWindow.SW_MAXIMIZE); + M.ResetMaximumBound(); M.WindowState = FormWindowState.Maximized; } if (value == "Minimized") { diff --git a/Tiefsee/WebWindow.cs b/Tiefsee/WebWindow.cs index a9a20dd..46fcdd0 100644 --- a/Tiefsee/WebWindow.cs +++ b/Tiefsee/WebWindow.cs @@ -50,6 +50,7 @@ public class WebWindow : FormNone { /// /// public WebWindow() { + ResetMaximumBound(); WebWindowList.Add(this); this.FormClosed += (sender, e) => { @@ -685,6 +686,22 @@ public void WindowRoundedCorners(bool enable) { WindowAPI.WindowRoundedCorners(this.Handle, enable); } + public void ResetMaximumBound() { + APPBARDATA abd = new APPBARDATA(); + abd.cbSize = Marshal.SizeOf(abd); + // 獲取任務欄狀態 + uint state = SHAppBarMessage(ABM_GETSTATE, ref abd); + + // 檢查是否啟用了自動隱藏 + if ((state & ABS_AUTOHIDE) == ABS_AUTOHIDE) { + var bounds = Screen.FromHandle(Handle).WorkingArea; + bounds.Height -= 1; + MaximizedBounds = bounds; + } + else { + MaximizedBounds = Screen.FromHandle(Handle).WorkingArea; + } + } } ///