#224, avoid restore window with non-positive client rect

This commit is contained in:
Kang Yu 2023-05-02 11:52:01 -07:00
parent a10e344604
commit c9d1eff0ad
2 changed files with 11 additions and 5 deletions

View file

@ -2079,17 +2079,20 @@ namespace PersistentWindows.Common
if (!User32.IsWindowVisible(hwnd))
continue;
*/
var rect = new RECT();
User32.GetWindowRect(hwnd, ref rect);
if (rect.Width <= 1 && rect.Height <= 1)
continue;
if (string.IsNullOrEmpty(GetWindowClassName(hwnd)))
continue;
if (string.IsNullOrEmpty(GetWindowTitle(hwnd)))
continue;
var rect = new RECT();
User32.GetWindowRect(hwnd, ref rect);
if (rect.Width <= 1 && rect.Height <= 1)
continue;
User32.GetClientRect(hwnd, out rect);
if (rect.Width <= 0 || rect.Height <= 0)
continue;
// workaround runtime overflow exception in release build
//SystemWindow window = new SystemWindow(hwnd);
//WindowStyleFlags style = window.Style;

View file

@ -212,6 +212,9 @@ namespace PersistentWindows.Common.WinApiBridge
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
[DllImport("user32.dll")]
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IntersectRect([Out] out RECT lprcDst, [In] ref RECT lprcSrc1, [In] ref RECT lprcSrc2);