Skip to content

Commit

Permalink
Added the possibility to get the state of a window (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Aug 2, 2023
1 parent f9d95e9 commit b590074
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion PermaTop/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,41 @@ public static string GetHiSentence
internal const int GWL_STYLE = -16;
internal const int WS_VISIBLE = 0x10000000;

public static SolidColorBrush GetSolidColor(string resource) => (SolidColorBrush)Application.Current.Resources[resource];
internal const int SW_SHOWNORMAL = 1;
internal const int SW_SHOWMINIMIZED = 2;
internal const int SW_SHOWMAXIMIZED = 3;

internal enum WindowPlacementFlags : int
{
WPF_SETMINPOSITION = 0x0001,
WPF_RESTORETOMAXIMIZED = 0x0002,
WPF_ASYNCWINDOWPLACEMENT = 0x0004
}

[StructLayout(LayoutKind.Sequential)]
internal struct WINDOWPLACEMENT
{
public int length;
public int flags;
public int showCmd;
public System.Drawing.Point ptMinPosition;
public System.Drawing.Point ptMaxPosition;
public System.Drawing.Rectangle rcNormalPosition;
}

[DllImport("user32.dll")]
internal static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);

internal static bool IsWindowMaximized(IntPtr windowHandle)
{
WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
placement.length = Marshal.SizeOf(placement);
GetWindowPlacement(windowHandle, ref placement);

return placement.showCmd == SW_SHOWMAXIMIZED;
}

internal static SolidColorBrush GetSolidColor(string resource) => (SolidColorBrush)Application.Current.Resources[resource];

// Import the SetWindowPos function from user32.dll
[DllImport("user32.dll")]
Expand Down

0 comments on commit b590074

Please sign in to comment.