Created
September 6, 2022 23:48
-
-
Save mattleibow/149cdd62a8df1a38cc36b276a3ae33aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public MainPage() | |
{ | |
InitializeComponent(); | |
#if WINDOWS | |
// WindowLongFlags | |
const int GWL_STYLE = -16; | |
const int GWL_EXSTYLE = -20; | |
// WindowStyles | |
const int WS_CAPTION = 0xc00000; | |
const int WS_THICKFRAME = 0x00040000; | |
const int WS_MINIMIZE = 0x20000000; | |
const int WS_MAXIMIZE = 0x01000000; | |
const int WS_SYSMENU = 0x00080000; | |
const int WS_EX_DLGMODALFRAME = 0x00000001; | |
const int WS_EX_CLIENTEDGE = 0x00000200; | |
const int WS_EX_STATICEDGE = 0x00020000; | |
// SetWindowPosFlags | |
const uint SWP_FRAMECHANGED = 0x0020; | |
const uint SWP_NOMOVE = 0x0002; | |
const uint SWP_NOSIZE = 0x0001; | |
const uint SWP_NOZORDER = 0x0004; | |
const uint SWP_NOOWNERZORDER = 0x0200; | |
Loaded += MainPage_Loaded; | |
void MainPage_Loaded(object sender, EventArgs e) | |
{ | |
var wnd = Window.Handler.PlatformView as Microsoft.UI.Xaml.Window; | |
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(wnd); | |
var lStyle = GetWindowLongPtr(hwnd, GWL_STYLE); | |
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU); | |
SetWindowLongPtr(hwnd, GWL_STYLE, lStyle); | |
var lExStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE); | |
lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE); | |
SetWindowLongPtr(hwnd, GWL_EXSTYLE, lExStyle); | |
SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER); | |
} | |
static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex) => | |
IntPtr.Size == 8 | |
? GetWindowLongPtr64(hWnd, nIndex) | |
: GetWindowLongPtr32(hWnd, nIndex); | |
static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong) => | |
IntPtr.Size == 8 | |
? SetWindowLongPtr64(hWnd, nIndex, dwNewLong) | |
: new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32())); | |
[DllImport("user32.dll", SetLastError = true)] | |
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); | |
[DllImport("user32.dll", EntryPoint = "GetWindowLong")] | |
static extern IntPtr GetWindowLongPtr32(IntPtr hWnd, int nIndex); | |
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")] | |
static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex); | |
[DllImport("user32.dll", EntryPoint = "SetWindowLong")] | |
static extern int SetWindowLong32(IntPtr hWnd, int nIndex, int dwNewLong); | |
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")] | |
static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong); | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment