From d280ad2a81fb8b2dc7493225d67a85177371aaed Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 22 Mar 2012 18:11:11 +0000 Subject: [PATCH] deal with initially hidden windows properly --- panda/src/windisplay/winGraphicsWindow.cxx | 37 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/panda/src/windisplay/winGraphicsWindow.cxx b/panda/src/windisplay/winGraphicsWindow.cxx index 5d97d650bf..691dcd124d 100644 --- a/panda/src/windisplay/winGraphicsWindow.cxx +++ b/panda/src/windisplay/winGraphicsWindow.cxx @@ -713,9 +713,40 @@ do_reshape_request(int x_origin, int y_origin, bool has_origin, void WinGraphicsWindow:: handle_reshape() { RECT view_rect; - GetClientRect(_hWnd, &view_rect); - ClientToScreen(_hWnd, (POINT*)&view_rect.left); // translates top,left pnt - ClientToScreen(_hWnd, (POINT*)&view_rect.right); // translates right,bottom pnt + if (!GetClientRect(_hWnd, &view_rect)) { + // Sometimes we get a "reshape" before the window is fully + // created, in which case GetClientRect() ought to fail. Ignore + // this. + if (windisplay_cat.is_debug()) { + windisplay_cat.debug() + << "GetClientRect() failed in handle_reshape. Ignoring.\n"; + } + return; + } + + // But in practice, GetClientRect() doesn't really fail, but just + // returns all zeroes. Ignore this too. + if (view_rect.left == 0 && view_rect.right == 0 && + view_rect.bottom == 0 && view_rect.top == 0) { + if (windisplay_cat.is_debug()) { + windisplay_cat.debug() + << "GetClientRect() returned all zeroes in handle_reshape. Ignoring.\n"; + } + return; + } + + bool result = ClientToScreen(_hWnd, (POINT*)&view_rect.left); // translates top,left pnt + if (result) { + result = ClientToScreen(_hWnd, (POINT*)&view_rect.right); // translates right,bottom pnt + } + + if (!result) { + if (windisplay_cat.is_debug()) { + windisplay_cat.debug() + << "ClientToScreen() failed in handle_reshape. Ignoring.\n"; + } + return; + } WindowProperties properties; properties.set_size((view_rect.right - view_rect.left),