mirror of
https://github.com/achiez/NebulaAuth-Steam-Desktop-Authenticator-by-Achies.git
synced 2026-07-25 14:24:32 +00:00
1e65cd4a06
NebulaAuth: - Added MAAC and PortableMaClient for multi-confirmations - Code clean-ups, removed unused classes, refactoring of old files - SteamLib updated - Localization and UI updates - Dependcies updated to the last version LegacyConverter: - Added mode to decrypt mafiles
115 lines
3.7 KiB
C#
115 lines
3.7 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Windows;
|
|
using System.Windows.Interop;
|
|
using System.Windows.Shell;
|
|
using Microsoft.Xaml.Behaviors;
|
|
|
|
namespace NebulaAuth.Theme.WindowStyle;
|
|
|
|
public class WindowChromeRenderedBehavior : Behavior<Window>
|
|
{
|
|
private Window? _window;
|
|
|
|
|
|
protected override void OnAttached()
|
|
{
|
|
base.OnAttached();
|
|
AssociatedObject.ContentRendered += OnContentRendered;
|
|
}
|
|
|
|
protected override void OnDetaching()
|
|
{
|
|
base.OnDetaching();
|
|
AssociatedObject.ContentRendered -= OnContentRendered;
|
|
}
|
|
|
|
private void OnContentRendered(object? sender, EventArgs e)
|
|
{
|
|
_window = Window.GetWindow(AssociatedObject);
|
|
|
|
if (_window == null) return;
|
|
|
|
var oldWindowChrome = WindowChrome.GetWindowChrome(_window);
|
|
|
|
if (oldWindowChrome == null) return;
|
|
|
|
var newWindowChrome = new WindowChrome
|
|
{
|
|
CaptionHeight = oldWindowChrome.CaptionHeight,
|
|
CornerRadius = oldWindowChrome.CornerRadius,
|
|
GlassFrameThickness = new Thickness(0, 0, 0, 1),
|
|
NonClientFrameEdges = NonClientFrameEdges.Bottom,
|
|
ResizeBorderThickness = oldWindowChrome.ResizeBorderThickness,
|
|
UseAeroCaptionButtons = oldWindowChrome.UseAeroCaptionButtons
|
|
};
|
|
|
|
WindowChrome.SetWindowChrome(_window, newWindowChrome);
|
|
|
|
var hWnd = new WindowInteropHelper(_window).Handle;
|
|
HwndSource.FromHwnd(hWnd)?.AddHook(WndProc);
|
|
}
|
|
|
|
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
|
{
|
|
switch (msg)
|
|
{
|
|
case NativeMethods.WM_NCPAINT:
|
|
handled = false;
|
|
RemoveFrame();
|
|
break;
|
|
case NativeMethods.WM_NCCALCSIZE:
|
|
handled = true;
|
|
var rcClientArea = (RECT)Marshal.PtrToStructure(lParam, typeof(RECT));
|
|
rcClientArea.Bottom += (int)(WindowChromeHelper.WindowResizeBorderThickness.Bottom / 2);
|
|
Marshal.StructureToPtr(rcClientArea, lParam, false);
|
|
|
|
return wParam == new IntPtr(1) ? new IntPtr((int)NativeMethods.WVR.REDRAW) : IntPtr.Zero;
|
|
}
|
|
|
|
return IntPtr.Zero;
|
|
}
|
|
|
|
private void RemoveFrame()
|
|
{
|
|
if (Environment.OSVersion.Version.Major >= 6 && NativeMethods.IsDwmAvailable())
|
|
{
|
|
if (NativeMethods.DwmIsCompositionEnabled() && SystemParameters.DropShadow)
|
|
{
|
|
// to get the aero shadow back, margins have to be set on at least one side
|
|
// don't use negative values for the margins because it causes flickering when restoring or maximizing the window
|
|
// setting the margin on the left or top sides seem best, since the window never appears to flicker there on resizing
|
|
// but the right and bottom sometimes do, otherwise there will occasionally be white flicker when resizing the window.
|
|
NativeMethods.MARGINS margins;
|
|
|
|
margins.bottomHeight = 0;
|
|
margins.leftWidth = 1;
|
|
margins.rightWidth = 0;
|
|
margins.topHeight = 0;
|
|
|
|
var helper = new WindowInteropHelper(_window);
|
|
|
|
NativeMethods.DwmExtendFrameIntoClientArea(helper.Handle, ref margins);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct RECT
|
|
{
|
|
public int Left;
|
|
public int Top;
|
|
public int Right;
|
|
public int Bottom;
|
|
public static RECT Empty;
|
|
|
|
public RECT(int left, int top, int right, int bottom)
|
|
{
|
|
Left = left;
|
|
Top = top;
|
|
Right = right;
|
|
Bottom = bottom;
|
|
}
|
|
}
|
|
} |