This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAboutWindow.xaml.cs
50 lines (44 loc) · 1.7 KB
/
AboutWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using Furtherance.Views;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using static PInvoke.User32;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace Furtherance;
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class AboutWindow : Window
{
public AboutWindow()
{
InitializeComponent();
Title = "About";
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
SetWindowDetails(hwnd, 300, 330);
var windowId = Win32Interop.GetWindowIdFromWindow(hwnd);
var appWindow = AppWindow.GetFromWindowId(windowId);
appWindow.SetIcon("Assets/furtherance.ico");
}
private static void SetWindowDetails(IntPtr hwnd, int width, int height)
{
var dpi = GetDpiForWindow(hwnd);
var scalingFactor = (float)dpi / 96;
width = (int)(width * scalingFactor);
height = (int)(height * scalingFactor);
_ = SetWindowPos(hwnd, SpecialWindowHandles.HWND_TOP,
0, 0, width, height,
SetWindowPosFlags.SWP_NOMOVE);
_ = SetWindowLong(hwnd,
WindowLongIndexFlags.GWL_STYLE,
(SetWindowLongFlags)(GetWindowLong(hwnd,
WindowLongIndexFlags.GWL_STYLE) &
~(int)SetWindowLongFlags.WS_MAXIMIZEBOX));
}
private void Window_Closed(object sender, WindowEventArgs args)
{
MainPage.mainPage.aboutWindow = null;
}
}