Skip to content

Commit

Permalink
Restore Launcher Window Animations (#2031)
Browse files Browse the repository at this point in the history
* Restoring Window Animations

Code for restoring the window animations

* Refactored window animation enable code to WindowsApi.cs

---------

Co-authored-by: Measurity <[email protected]>
  • Loading branch information
NinjaPedroX and Measurity authored Apr 27, 2023
1 parent 54d4043 commit 03a221b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
3 changes: 2 additions & 1 deletion NitroxLauncher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
Title="Nitrox Launcher" Height="642" MinHeight="642" Width="1024" MinWidth="1024"
WindowStyle="None" WindowStartupLocation="CenterScreen"
Closing="OnClosing"
Background="Black">
Background="Black"
Loaded="Window_Loaded">

<Window.Resources>
<BitmapImage x:Key="SidebarNitroxLogo" UriSource="pack://application:,,,/Assets/Images/nitroxLogo.png" />
Expand Down
15 changes: 11 additions & 4 deletions NitroxLauncher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel;
using System.IO;
using System.Net.NetworkInformation;
Expand All @@ -7,11 +7,13 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using NitroxLauncher.Models.Events;
using NitroxLauncher.Models.Properties;
using NitroxLauncher.Pages;
using NitroxModel.Discovery;
using NitroxModel.Helper;
using NitroxModel.Platforms.OS.Windows;

namespace NitroxLauncher
{
Expand Down Expand Up @@ -41,7 +43,7 @@ public MainWindow()
{
Log.Setup();
LauncherNotifier.Setup();

logic = new LauncherLogic();

MaxHeight = SystemParameters.VirtualScreenHeight;
Expand All @@ -66,7 +68,7 @@ public MainWindow()
MessageBoxImage.Error);
Environment.Exit(1);
}
// This pirate detection subscriber is immediately invoked if pirate has been detected right now.
PirateDetection.PirateDetected += (o, eventArgs) =>
{
Expand All @@ -78,7 +80,7 @@ public MainWindow()
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
Margin = new Thickness(0),
Height = MinHeight * 0.7,
Width = MinWidth * 0.7
};
Expand Down Expand Up @@ -216,5 +218,10 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
WindowsApi.EnableDefaultWindowAnimations(new WindowInteropHelper(this).Handle);
}
}
}
38 changes: 38 additions & 0 deletions NitroxModel/Platforms/OS/Windows/Internal/Win32Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,44 @@ private enum UIContext
Install
}

[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
internal static extern int SetWindowLong32(HandleRef hWnd, int nIndex, int dwNewLong);

[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
internal static extern IntPtr SetWindowLongPtr64(HandleRef hWnd, int nIndex, IntPtr dwNewLong);

[Flags]
public enum WS : long
{
WS_BORDER = 0x00800000L,
WS_CAPTION = 0x00C00000L,
WS_CHILD = 0x40000000L,
WS_CHILDWINDOW = 0x40000000L,
WS_CLIPCHILDREN = 0x02000000L,
WS_CLIPSIBLINGS = 0x04000000L,
WS_DISABLED = 0x08000000L,
WS_DLGFRAME = 0x00400000L,
WS_GROUP = 0x00020000L,
WS_HSCROLL = 0x00100000L,
WS_ICONIC = 0x20000000L,
WS_MAXIMIZE = 0x01000000L,
WS_MAXIMIZEBOX = 0x00010000L,
WS_MINIMIZE = 0x20000000L,
WS_MINIMIZEBOX = 0x00020000L,
WS_OVERLAPPED = 0x00000000L,
WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
WS_POPUP = 0x80000000L,
WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU,
WS_SIZEBOX = 0x00040000L,
WS_SYSMENU = 0x00080000L,
WS_TABSTOP = 0x00010000L,
WS_THICKFRAME = 0x00040000L,
WS_TILED = 0x00000000L,
WS_TILEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
WS_VISIBLE = 0x10000000L,
WS_VSCROLL = 0x00200000L
}

[StructLayout(LayoutKind.Sequential)]
private struct WINTRUST_DATA : IDisposable
{
Expand Down
26 changes: 26 additions & 0 deletions NitroxModel/Platforms/OS/Windows/WindowsApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Runtime.InteropServices;
using NitroxModel.Platforms.OS.Windows.Internal;

namespace NitroxModel.Platforms.OS.Windows;

public class WindowsApi
{
public static void EnableDefaultWindowAnimations(IntPtr hWnd, int nIndex = -16)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
IntPtr dwNewLong = new((long)(Win32Native.WS.WS_CAPTION | Win32Native.WS.WS_CLIPCHILDREN | Win32Native.WS.WS_MINIMIZEBOX | Win32Native.WS.WS_MAXIMIZEBOX | Win32Native.WS.WS_SYSMENU | Win32Native.WS.WS_SIZEBOX));
HandleRef handle = new(null, hWnd);
switch (IntPtr.Size)
{
case 8:
Win32Native.SetWindowLongPtr64(handle, nIndex, dwNewLong);
break;
default:
Win32Native.SetWindowLong32(handle, nIndex, dwNewLong.ToInt32());
break;
}
}
}
}

0 comments on commit 03a221b

Please sign in to comment.