1- using System . ComponentModel ;
21using Avalonia ;
2+ using Avalonia . Collections ;
33using Avalonia . Controls ;
4+ using Avalonia . Controls . ApplicationLifetimes ;
5+ using Avalonia . Controls . Metadata ;
6+ using Avalonia . Controls . Presenters ;
47using Avalonia . Controls . Primitives ;
58using Avalonia . Input ;
6- using Avalonia . Media ;
7- using Avalonia . Collections ;
8- using Avalonia . Controls . ApplicationLifetimes ;
99using Avalonia . Interactivity ;
10- using SukiUI . Enums ;
11- using System . Runtime . InteropServices ;
12- using Avalonia . Controls . Metadata ;
1310using Avalonia . Layout ;
11+ using Avalonia . Media ;
1412using Avalonia . Threading ;
15- using Avalonia . Controls . Presenters ;
13+ using SukiUI . Enums ;
1614using SukiUI . Extensions ;
15+ using System . ComponentModel ;
16+ using System . Runtime . InteropServices ;
1717
1818namespace SukiUI . Controls ;
1919
@@ -832,12 +832,27 @@ private void ShowTitleBarTimerOnTick(object sender, EventArgs e)
832832 }
833833 #endregion
834834
835- #region Methods
835+ #region Methods
836+ [ DllImport ( "user32.dll" ) ]
837+ static extern short GetAsyncKeyState ( int vKey ) ;
838+
839+ public static bool IsMouseDown ( )
840+ {
841+ const int VK_LBUTTON = 1 ;
842+
843+ if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
844+ {
845+ return false ;
846+ }
847+
848+ return ( GetAsyncKeyState ( VK_LBUTTON ) & 0x8000 ) != 0 ;
849+ }
850+
836851 private void EnableWindowsSnapLayout ( Button maximize )
837- {
852+ {
853+ const int HTCLIENT = 1 ;
838854 const int HTMAXBUTTON = 9 ;
839855 const uint WM_NCHITTEST = 0x0084 ;
840- const uint WM_CAPTURECHANGED = 0x0215 ;
841856
842857 var pointerOnButton = false ;
843858 var pointerOverSetter = typeof ( Button ) . GetProperty ( nameof ( IsPointerOver ) ) ;
@@ -868,9 +883,9 @@ nint ProcHookCallback(nint hWnd, uint msg, nint wParam, nint lParam, ref bool ha
868883 {
869884 pointerOnButton = true ;
870885 pointerOverSetter . SetValue ( maximize , true ) ;
871- }
872-
873- return HTMAXBUTTON ;
886+ }
887+
888+ return IsMouseDown ( ) ? HTCLIENT : HTMAXBUTTON ;
874889 }
875890 else
876891 {
@@ -880,19 +895,8 @@ nint ProcHookCallback(nint hWnd, uint msg, nint wParam, nint lParam, ref bool ha
880895 pointerOverSetter . SetValue ( maximize , false ) ;
881896 }
882897 }
883- }
884- else if ( msg == WM_CAPTURECHANGED )
885- {
886- if ( pointerOnButton && CanMaximize )
887- {
888- WindowState = WindowState == WindowState . Maximized
889- ? WindowState . Normal
890- : WindowState . Maximized ;
891-
892- pointerOverSetter . SetValue ( maximize , false ) ;
893- }
894- }
895-
898+ }
899+
896900 return 0 ;
897901 }
898902
0 commit comments