diff --git a/Tiefsee/Lib/WindowAPI.cs b/Tiefsee/Lib/WindowAPI.cs index c18b101..6caa77b 100644 --- a/Tiefsee/Lib/WindowAPI.cs +++ b/Tiefsee/Lib/WindowAPI.cs @@ -286,6 +286,48 @@ 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; + + + public const uint ABM_GETTASKBARPOS = 0x00000005; + + // 設定任務欄的狀態,當值為 ABS_AUTOHIDE 時,表示啟用了自動隱藏 + public const int ABS_AUTOHIDE = 0x1; + + // APPBARDATA edge 可能的值 + public const uint ABE_LEFT = 0; + public const uint ABE_TOP = 1; + public const uint ABE_RIGHT = 2; + public const uint ABE_BOTTOM = 3; + + #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..891a6e6 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,45 @@ 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) { + state = SHAppBarMessage(ABM_GETTASKBARPOS, ref abd); + var bounds = Screen.FromHandle(Handle).WorkingArea; + bounds.X = 0; + bounds.Y = 0; + if (state == 1) { + switch (abd.uEdge) { + case ABE_TOP: + bounds.Y += 1; + bounds.Height -= 1; + break; + case ABE_BOTTOM: + bounds.Height -= 1; + break; + case ABE_LEFT: + bounds.X += 1; + bounds.Width -= 1; + break; + case ABE_RIGHT: + bounds.Width -= 1; + break; + } + } + MaximizedBounds = bounds; + } + else { + var bounds = Screen.FromHandle(Handle).WorkingArea; + bounds.X = 0; + bounds.Y = 0; + MaximizedBounds = bounds; + } + } } ///