-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #508 from ghost1372/Fix-TitleBar3
Use WASDK v1.4 new Custom TitleBar API, Simplify Calculating Rects and Fix TitleBar Drag Region for Scale 125%
- Loading branch information
Showing
5 changed files
with
295 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Windows.ApplicationModel; | ||
using Windows.Storage; | ||
using Windows.System.Profile; | ||
|
||
namespace CommunityToolkit.WinUI.Controls; | ||
internal static class InfoHelper | ||
{ | ||
public static Version AppVersion { get; } = new Version( | ||
Package.Current.Id.Version.Major, | ||
Package.Current.Id.Version.Minor, | ||
Package.Current.Id.Version.Build, | ||
Package.Current.Id.Version.Revision | ||
); | ||
|
||
public static Version SystemVersion { get; } | ||
|
||
public static SystemDataPaths SystemDataPath { get; } = SystemDataPaths.GetDefault(); | ||
|
||
public static UserDataPaths UserDataPath { get; } = UserDataPaths.GetDefault(); | ||
|
||
public static string AppInstalledLocation { get; } = Package.Current.InstalledLocation.Path; | ||
|
||
static InfoHelper() | ||
{ | ||
string systemVersion = AnalyticsInfo.VersionInfo.DeviceFamilyVersion; | ||
ulong version = ulong.Parse(systemVersion); | ||
SystemVersion = new Version( | ||
(int)((version & 0xFFFF000000000000L) >> 48), | ||
(int)((version & 0x0000FFFF00000000L) >> 32), | ||
(int)((version & 0x00000000FFFF0000L) >> 16), | ||
(int)(version & 0x000000000000FFFFL) | ||
); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,84 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#if WINAPPSDK | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace CommunityToolkit.WinUI.Controls; | ||
|
||
internal static class NativeMethods | ||
{ | ||
[DllImport("Shcore.dll", SetLastError = true)] | ||
internal static extern int GetDpiForMonitor(IntPtr hmonitor, Monitor_DPI_Type dpiType, out uint dpiX, out uint dpiY); | ||
public enum WindowMessage : int | ||
{ | ||
WM_NCLBUTTONDOWN = 0x00A1, | ||
WM_NCRBUTTONDOWN = 0x00A4, | ||
WM_SYSCOMMAND = 0x0112, | ||
WM_SYSMENU = 0x0313, | ||
WM_GETMINMAXINFO = 0x0024 | ||
} | ||
[Flags] | ||
public enum WindowStyle : uint | ||
{ | ||
WS_SYSMENU = 0x80000 | ||
} | ||
|
||
internal enum Monitor_DPI_Type : int | ||
[Flags] | ||
public enum WindowLongIndexFlags : int | ||
{ | ||
MDT_Effective_DPI = 0, | ||
MDT_Angular_DPI = 1, | ||
MDT_Raw_DPI = 2, | ||
MDT_Default = MDT_Effective_DPI | ||
GWL_WNDPROC = -4, | ||
GWL_STYLE = -16 | ||
} | ||
|
||
[Flags] | ||
public enum SetWindowPosFlags : uint | ||
{ | ||
/// <summary> | ||
/// Retains the current position (ignores X and Y parameters). | ||
/// </summary> | ||
SWP_NOMOVE = 0x0002 | ||
} | ||
|
||
public enum SystemCommand | ||
{ | ||
SC_MOUSEMENU = 0xF090, | ||
SC_KEYMENU = 0xF100 | ||
} | ||
|
||
[DllImport("user32.dll", EntryPoint = "GetWindowLongW", SetLastError = false)] | ||
public static extern int GetWindowLong(IntPtr hWnd, int nIndex); | ||
|
||
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtrW", SetLastError = false)] | ||
public static extern int GetWindowLongPtr(IntPtr hWnd, int nIndex); | ||
|
||
public static int GetWindowLongAuto(IntPtr hWnd, int nIndex) | ||
{ | ||
if (IntPtr.Size is 8) | ||
{ | ||
return GetWindowLongPtr(hWnd, nIndex); | ||
} | ||
else | ||
{ | ||
return GetWindowLong(hWnd, nIndex); | ||
} | ||
} | ||
|
||
[DllImport("user32.dll", EntryPoint = "FindWindowExW", SetLastError = true, CharSet = CharSet.Unicode)] | ||
public static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr hWndChildAfter, string lpszClass, string lpszWindow); | ||
|
||
|
||
[DllImport("user32.dll", EntryPoint = "SetWindowLongW", SetLastError = false)] | ||
public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong); | ||
|
||
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtrW", SetLastError = false)] | ||
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong); | ||
|
||
public static IntPtr SetWindowLongAuto(IntPtr hWnd, int nIndex, IntPtr dwNewLong) | ||
{ | ||
if (IntPtr.Size is 8) | ||
{ | ||
return SetWindowLongPtr(hWnd, nIndex, dwNewLong); | ||
} | ||
else | ||
{ | ||
return SetWindowLong(hWnd, nIndex, dwNewLong); | ||
} | ||
} | ||
|
||
[DllImport("user32.dll")] | ||
public static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam); | ||
} | ||
#endif |
This file contains 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
Oops, something went wrong.