Skip to content

Commit

Permalink
v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliviaophia committed Apr 10, 2022
1 parent f9a54e0 commit f6f970e
Show file tree
Hide file tree
Showing 20 changed files with 533 additions and 237 deletions.
2 changes: 1 addition & 1 deletion Sources/SmartTaskbar.WapProj/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Identity
Name="20535Chanple.SmartTaskbar"
Publisher="CN=F5F524C9-8FE8-4344-A509-F43DDE3B3ED6"
Version="1.3.4.0" />
Version="1.4.0.0" />

<Properties>
<DisplayName>SmartTaskbar</DisplayName>
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmartTaskbar.WapProj/SmartTaskbar.WapProj.wapproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<PropertyGroup>
<ProjectGuid>4bb030e8-5894-4ca4-b80b-ead44b9b4de4</ProjectGuid>
<TargetPlatformVersion>10.0.22000.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.22000.0</TargetPlatformMinVersion>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<DefaultLanguage>zh-CN</DefaultLanguage>
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
<NoWarn>$(NoWarn);NU1702</NoWarn>
Expand Down
23 changes: 12 additions & 11 deletions Sources/SmartTaskbar.Win10/Helpers/AutoHideHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,44 @@ public static partial class Fun
private const uint AbmSetState = 10;

private const uint AbmGetState = 4;
private static AppbarData _msg;

/// <summary>
/// Set taskbar to Auto-Hide
/// </summary>
public static void SetAutoHide()
{
var msg = new AppbarData();
if (SHAppBarMessage(AbmGetState, ref msg) != IntPtr.Zero)
if (!IsNotAutoHide())
return;

msg.lParam = AbsAutoHide;
_msg.lParam = AbsAutoHide;

_ = SHAppBarMessage(AbmSetState, ref msg);
_ = SHAppBarMessage(AbmSetState, ref _msg);
}

public static bool IsNotAutoHide()
=> SHAppBarMessage(AbmGetState, ref _msg) == IntPtr.Zero;

/// <summary>
/// Change Auto-Hide status
/// </summary>
public static void ChangeAutoHide()
{
var msg = new AppbarData();
msg.lParam = SHAppBarMessage(AbmGetState, ref msg) == IntPtr.Zero ? AbsAutoHide : AbsAlwaysOnTop;
_ = SHAppBarMessage(AbmSetState, ref msg);
_msg.lParam = IsNotAutoHide() ? AbsAutoHide : AbsAlwaysOnTop;
_ = SHAppBarMessage(AbmSetState, ref _msg);
}

/// <summary>
/// Set taskbar to Always-On-Top
/// </summary>
public static void CancelAutoHide()
{
var msg = new AppbarData();
if (SHAppBarMessage(AbmGetState, ref msg) == IntPtr.Zero)
if (IsNotAutoHide())
return;

msg.lParam = AbsAlwaysOnTop;
_msg.lParam = AbsAlwaysOnTop;

_ = SHAppBarMessage(AbmSetState, ref msg);
_ = SHAppBarMessage(AbmSetState, ref _msg);
}
}
}
30 changes: 19 additions & 11 deletions Sources/SmartTaskbar.Win10/Views/SystemTray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ private void NotifyIconOnMouseDoubleClick(object s, MouseEventArgs e)
{
UserSettings.AutoModeType = AutoModeType.None;
Fun.ChangeAutoHide();
HideBar();
}

private static void HideBar()
{
if (Fun.IsNotAutoHide())
return;

var taskbar = TaskbarHelper.InitTaskbar();

if (taskbar.Handle != IntPtr.Zero)
Expand All @@ -125,15 +133,7 @@ private void NotifyIconOnMouseClick(object s, MouseEventArgs e)

_showTaskbarWhenExit.Checked = UserSettings.ShowTaskbarWhenExit;

switch (UserSettings.AutoModeType)
{
case AutoModeType.Auto:
_autoMode.Checked = true;
break;
case AutoModeType.None:
_autoMode.Checked = false;
break;
}
_autoMode.Checked = UserSettings.AutoModeType == AutoModeType.Auto;

ShowMenu();

Expand Down Expand Up @@ -194,16 +194,24 @@ private void ExitOnClick(object s, EventArgs e)
{
if (UserSettings.ShowTaskbarWhenExit)
Fun.CancelAutoHide();
else
HideBar();
_container?.Dispose();
Application.Exit();
}

private void AutoModeOnClick(object s, EventArgs e)
{
UserSettings.AutoModeType = _autoMode.Checked ? AutoModeType.None : AutoModeType.Auto;
if (_autoMode.Checked)
{
UserSettings.AutoModeType = AutoModeType.None;
HideBar();
}
else { UserSettings.AutoModeType = AutoModeType.Auto; }
}

private void AnimationOnClick(object s, EventArgs e) { _animation.Checked = Fun.ChangeTaskbarAnimation(); }
private void AnimationOnClick(object s, EventArgs e)
=> _animation.Checked = Fun.ChangeTaskbarAnimation();

private void AboutOnClick(object s, EventArgs e)
{
Expand Down
23 changes: 12 additions & 11 deletions Sources/SmartTaskbar/Helpers/AutoHideHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,44 @@ public static partial class Fun
private const uint AbmSetState = 10;

private const uint AbmGetState = 4;
private static AppbarData _msg;

/// <summary>
/// Set taskbar to Auto-Hide
/// </summary>
public static void SetAutoHide()
{
var msg = new AppbarData();
if (SHAppBarMessage(AbmGetState, ref msg) != IntPtr.Zero)
if (!IsNotAutoHide())
return;

msg.lParam = AbsAutoHide;
_msg.lParam = AbsAutoHide;

_ = SHAppBarMessage(AbmSetState, ref msg);
_ = SHAppBarMessage(AbmSetState, ref _msg);
}

public static bool IsNotAutoHide()
=> SHAppBarMessage(AbmGetState, ref _msg) == IntPtr.Zero;

/// <summary>
/// Change Auto-Hide status
/// </summary>
public static void ChangeAutoHide()
{
var msg = new AppbarData();
msg.lParam = SHAppBarMessage(AbmGetState, ref msg) == IntPtr.Zero ? AbsAutoHide : AbsAlwaysOnTop;
_ = SHAppBarMessage(AbmSetState, ref msg);
_msg.lParam = IsNotAutoHide() ? AbsAutoHide : AbsAlwaysOnTop;
_ = SHAppBarMessage(AbmSetState, ref _msg);
}

/// <summary>
/// Set taskbar to Always-On-Top
/// </summary>
public static void CancelAutoHide()
{
var msg = new AppbarData();
if (SHAppBarMessage(AbmGetState, ref msg) == IntPtr.Zero)
if (IsNotAutoHide())
return;

msg.lParam = AbsAlwaysOnTop;
_msg.lParam = AbsAlwaysOnTop;

_ = SHAppBarMessage(AbmSetState, ref msg);
_ = SHAppBarMessage(AbmSetState, ref _msg);
}
}
}
115 changes: 48 additions & 67 deletions Sources/SmartTaskbar/Helpers/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,24 @@ [Out] [MarshalAs(UnmanagedType.LPWStr)]
/// <param name="strWindowName"></param>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow([In] string? strClassName, [In] string? strWindowName);
public static extern IntPtr FindWindow([In] string strClassName, [In] string strWindowName);

#endregion

#region GetWindowRect

/// <summary>
/// Retrieves the dimensions of the bounding rectangle of the specified window.
/// The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
/// </summary>
/// <param name="hWnd"></param>
/// <param name="lpRect"></param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "GetWindowRect")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect([In] IntPtr hWnd, out TagRect lpRect);

#endregion

Expand All @@ -190,23 +207,24 @@ [Out] [MarshalAs(UnmanagedType.LPWStr)]

#endregion

#region Taskbar Display State

[StructLayout(LayoutKind.Sequential)]
public struct AppbarData
{
public uint cbSize;

public IntPtr hWnd;
#region SendNotifyMessage

public uint uCallbackMessage;

public uint uEdge;
/// <summary>
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
/// </summary>
/// <param name="hWnd"></param>
/// <param name="msg"></param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
/// <returns></returns>
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SendNotifyMessage(IntPtr hWnd, uint msg, UIntPtr wParam, string lParam);

public TagRect rc;
#endregion

public int lParam;
}
#region Taskbar Display State

/// <summary>
/// This function returns a message-dependent value.
Expand All @@ -219,6 +237,21 @@ public struct AppbarData

#endregion

#region WindowFromPoint

/// <summary>
/// The return value is a handle to the window that contains the point.
/// If no window exists at the given point, the return value is NULL.
/// If the point is over a static text control, the return value is a handle to the window under the static text
/// control.
/// </summary>
/// <param name="point"></param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "WindowFromPoint")]
public static extern IntPtr WindowFromPoint(TagPoint point);

#endregion

#region SystemParametersInfo

/// <summary>
Expand Down Expand Up @@ -248,57 +281,5 @@ public struct AppbarData
public static extern bool GetSystemParameters(uint uiAction, uint uiParam, out bool pvParam, uint fWinIni);

#endregion

#region GetWindowRect

/// <summary>
/// Retrieves the dimensions of the bounding rectangle of the specified window.
/// The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
/// </summary>
/// <param name="hWnd"></param>
/// <param name="lpRect"></param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "GetWindowRect")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect([In] IntPtr hWnd, out TagRect lpRect);

[StructLayout(LayoutKind.Sequential)]
public struct TagRect
{
public int left;

public int top;

public int right;

public int bottom;
}

#endregion

#region WindowFromPoint

/// <summary>
/// The return value is a handle to the window that contains the point.
/// If no window exists at the given point, the return value is NULL.
/// If the point is over a static text control, the return value is a handle to the window under the static text
/// control.
/// </summary>
/// <param name="point"></param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "WindowFromPoint")]
public static extern IntPtr WindowFromPoint(TagPoint point);

[StructLayout(LayoutKind.Sequential)]
public struct TagPoint
{
public int x;

public int y;
}

#endregion
}
}
4 changes: 0 additions & 4 deletions Sources/SmartTaskbar/Languages/LangName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,5 @@ public static class LangName
public const string TrayExit = "tray_exit";

public const string TrayShowBarOnExit = "tray_showBarOnExit";

public const string TrayDebug = "tray_debug";

public const string ShowNoFindInfo = "show_noFindInfo";
}
}
10 changes: 2 additions & 8 deletions Sources/SmartTaskbar/Languages/Resource.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,11 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="show_noFindInfo" xml:space="preserve">
<value>Can't get window information</value>
</data>
<data name="tray_about" xml:space="preserve">
<value>About</value>
</data>
Expand All @@ -129,9 +126,6 @@
<data name="tray_auto" xml:space="preserve">
<value>Auto Mode</value>
</data>
<data name="tray_debug" xml:space="preserve">
<value>Last hidden reason</value>
</data>
<data name="tray_exit" xml:space="preserve">
<value>Exit</value>
</data>
Expand Down
10 changes: 2 additions & 8 deletions Sources/SmartTaskbar/Languages/Resource.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,11 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="show_noFindInfo" xml:space="preserve">
<value>找不到窗口信息</value>
</data>
<data name="tray_about" xml:space="preserve">
<value>关于</value>
</data>
Expand All @@ -129,9 +126,6 @@
<data name="tray_auto" xml:space="preserve">
<value>智能模式</value>
</data>
<data name="tray_debug" xml:space="preserve">
<value>最后隐藏原因</value>
</data>
<data name="tray_exit" xml:space="preserve">
<value>退出</value>
</data>
Expand Down
Loading

0 comments on commit f6f970e

Please sign in to comment.