reliably restore full screen window by simulating double clicking

This commit is contained in:
Kang Yu 2024-10-18 18:42:45 -07:00
parent 23fd772152
commit a515bd6e6e

View file

@ -3364,6 +3364,7 @@ namespace PersistentWindows.Common
long style = User32.GetWindowLong(hwnd, User32.GWL_STYLE); long style = User32.GetWindowLong(hwnd, User32.GWL_STYLE);
if ((style & (long)WindowStyleFlags.CAPTION) == 0L) if ((style & (long)WindowStyleFlags.CAPTION) == 0L)
{ {
Log.Error("no need to restore full screen window {0}", GetWindowTitle(hwnd));
return; return;
/* /*
style |= (long)WindowStyleFlags.CAPTION; style |= (long)WindowStyleFlags.CAPTION;
@ -3397,7 +3398,6 @@ namespace PersistentWindows.Common
int centerx = screenPosition.Left + screenPosition.Width / 8; int centerx = screenPosition.Left + screenPosition.Width / 8;
int centery = screenPosition.Top + 15; int centery = screenPosition.Top + 15;
//User32.SetActiveWindow(hwnd);
User32.SetCursorPos(centerx, centery); User32.SetCursorPos(centerx, centery);
int double_clck_interval = System.Windows.Forms.SystemInformation.DoubleClickTime / 2; int double_clck_interval = System.Windows.Forms.SystemInformation.DoubleClickTime / 2;
User32.mouse_event(MouseAction.MOUSEEVENTF_LEFTDOWN | MouseAction.MOUSEEVENTF_LEFTUP, User32.mouse_event(MouseAction.MOUSEEVENTF_LEFTDOWN | MouseAction.MOUSEEVENTF_LEFTUP,
@ -3405,18 +3405,31 @@ namespace PersistentWindows.Common
Thread.Sleep(double_clck_interval); Thread.Sleep(double_clck_interval);
User32.mouse_event(MouseAction.MOUSEEVENTF_LEFTDOWN | MouseAction.MOUSEEVENTF_LEFTUP, User32.mouse_event(MouseAction.MOUSEEVENTF_LEFTDOWN | MouseAction.MOUSEEVENTF_LEFTUP,
0, 0, 0, UIntPtr.Zero); 0, 0, 0, UIntPtr.Zero);
Thread.Sleep(double_clck_interval); Log.Error("restore full screen window {0}", GetWindowTitle(hwnd));
Thread.Sleep(3 * double_clck_interval);
style = User32.GetWindowLong(hwnd, User32.GWL_STYLE); style = User32.GetWindowLong(hwnd, User32.GWL_STYLE);
if ((style & (long)WindowStyleFlags.CAPTION) == 0L) if ((style & (long)WindowStyleFlags.CAPTION) == 0L)
{ {
Log.Error("restore full screen window {0}", GetWindowTitle(hwnd));
return; return;
} }
User32.mouse_event(MouseAction.MOUSEEVENTF_LEFTDOWN | MouseAction.MOUSEEVENTF_LEFTUP, User32.mouse_event(MouseAction.MOUSEEVENTF_LEFTDOWN | MouseAction.MOUSEEVENTF_LEFTUP,
0, 0, 0, UIntPtr.Zero); 0, 0, 0, UIntPtr.Zero);
Thread.Sleep(double_clck_interval);
User32.mouse_event(MouseAction.MOUSEEVENTF_LEFTDOWN | MouseAction.MOUSEEVENTF_LEFTUP,
0, 0, 0, UIntPtr.Zero);
Log.Error("double restore full screen window {0}", GetWindowTitle(hwnd)); Log.Error("double restore full screen window {0}", GetWindowTitle(hwnd));
Thread.Sleep(3 * double_clck_interval);
style = User32.GetWindowLong(hwnd, User32.GWL_STYLE);
if ((style & (long)WindowStyleFlags.CAPTION) == 0L)
{
return;
}
Log.Error("fail to restore full screen window {0}", GetWindowTitle(hwnd));
} }
private void RestoreSnapWindow(IntPtr hwnd, RECT target_pos) private void RestoreSnapWindow(IntPtr hwnd, RECT target_pos)