From c1fd29df7ac73ca85c0d3e0e2d9da92af250c9c4 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Fri, 7 Mar 2014 12:28:40 +0800 Subject: [PATCH] Fix The Win32 Backend for Newer Visual Studio Versions The GetSystemMetrics() function returns wrong values for SM_CXSIZEFRAME, SM_CYSIZEFRAME, SM_CXFIXEDFRAME and SM_CYFIXEDFRAME when built with Visual Studio 2012 and 2013 (unless the XP compatibility setting for the PlatformToolset entry is turned on), causing the window of Clutter programs to automatically shrink to a point where they become unusable. This patch uses AdjustWindowRectEx() for builds using Visual Studio 2012 and later, which deduces the required height and width of the Window properly. Unfortunately we can't use this for the VS 2008/2010 builds as they cause the Window to continually expand as the program is run. https://bugzilla.gnome.org/show_bug.cgi?id=725873 --- clutter/win32/clutter-stage-win32.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/clutter/win32/clutter-stage-win32.c b/clutter/win32/clutter-stage-win32.c index bcc39a7d3..cdc1fc69b 100644 --- a/clutter/win32/clutter-stage-win32.c +++ b/clutter/win32/clutter-stage-win32.c @@ -138,11 +138,26 @@ get_full_window_size (ClutterStageWin32 *stage_win32, = clutter_stage_get_user_resizable (stage_win32->wrapper); /* The window size passed to CreateWindow includes the window decorations */ - *width_out = width_in + GetSystemMetrics (resizable ? SM_CXSIZEFRAME - : SM_CXFIXEDFRAME) * 2; - *height_out = height_in + GetSystemMetrics (resizable ? SM_CYSIZEFRAME - : SM_CYFIXEDFRAME) * 2 - + GetSystemMetrics (SM_CYCAPTION); + gint frame_width, frame_height; + +#if !defined (_MSC_VER) || (_MSC_VER < 1700) + frame_width = GetSystemMetrics (resizable ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME); + frame_height = GetSystemMetrics (resizable ? SM_CYSIZEFRAME : SM_CYFIXEDFRAME); +#else + /* MSVC 2012 and later returns wrong values from GetSystemMetrics() + * http://connect.microsoft.com/VisualStudio/feedback/details/753224/regression-getsystemmetrics-delivers-different-values + * + * For AdjustWindowRectEx(), it doesn't matter much whether the Window is resizble. + */ + + RECT cxrect = {0, 0, 0, 0}; + AdjustWindowRectEx (&cxrect, WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_THICKFRAME | WS_DLGFRAME, FALSE, 0); + + frame_width = abs (cxrect.bottom); + frame_height = abs (cxrect.left); +#endif + *width_out = width_in + frame_width * 2; + *height_out = height_in + frame_height * 2 + GetSystemMetrics (SM_CYCAPTION); } void