Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix toggle taskbar hidden when window is maximized #55

Merged
merged 3 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Tiefsee/Lib/WindowAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
1 change: 1 addition & 0 deletions Tiefsee/VW/WV_Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
40 changes: 40 additions & 0 deletions Tiefsee/WebWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class WebWindow : FormNone {
///
/// </summary>
public WebWindow() {
ResetMaximumBound();
WebWindowList.Add(this);

this.FormClosed += (sender, e) => {
Expand Down Expand Up @@ -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;
}
}
}

/// <summary>
Expand Down