0023628: Snapshots have wrong dimension when OCCT is built by VC++ 11
authorkgv <kgv@opencascade.com>
Mon, 17 Dec 2012 08:44:37 +0000 (12:44 +0400)
committerRoman Lygin <roman.lygin@gmail.com>
Fri, 28 Dec 2012 14:05:45 +0000 (18:05 +0400)
Use AdjustWindowRect() function to adjust window rectangle instead of
manual GetSystemMetrics().

src/Draw/Draw_Window.cxx
src/WNT/WNT_Window.cxx

index c3d778a..8710e73 100755 (executable)
 // purpose or non-infringement. Please see the License for the specific terms
 // and conditions governing the rights and limitations under the License.
 
-// Updated by DPF Fri Mar 21 18:40:58 1997
-//              Added casting in void to compile
-//              on AO1 int 32 bits -> pointer 64 bits ????
-// Robert Boehne 30 May 2000 : Dec Osf
-
 // include windows.h first to have all definitions available
 #ifdef WNT
 #include <windows.h>
@@ -1474,13 +1469,19 @@ void DrawWindow::Init(Standard_Integer theXLeft, Standard_Integer theYTop,
 
   // include decorations in the window dimensions
   // to reproduce same behaviour of Xlib window.
-  theXLeft   -= GetSystemMetrics(SM_CXSIZEFRAME);
-  theYTop    -= GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYCAPTION);
-  theWidth   += 2 * GetSystemMetrics(SM_CXSIZEFRAME);
-  theHeight  += 2 * GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYCAPTION);
+  DWORD aWinStyle   = GetWindowLongPtr (win, GWL_STYLE);
+  DWORD aWinStyleEx = GetWindowLongPtr (win, GWL_EXSTYLE);
+  HMENU aMenu       = GetMenu (win);
 
-  SetPosition (theXLeft, theYTop);
-  SetDimension (theWidth, theHeight);
+  RECT aRect;
+  aRect.top    = theYTop;
+  aRect.bottom = theYTop + theHeight;
+  aRect.left   = theXLeft;
+  aRect.right  = theXLeft + theWidth;
+  AdjustWindowRectEx (&aRect, aWinStyle, aMenu != NULL ? TRUE : FALSE, aWinStyleEx);
+
+  SetPosition  (aRect.left, aRect.top);
+  SetDimension (aRect.right - aRect.left, aRect.bottom - aRect.top);
   // Save the pointer at the instance associated to the window
   SetWindowLong(win, CLIENTWND, (LONG)this);
   HDC hDC = GetDC(win);
index 134e1e6..8c617da 100755 (executable)
@@ -119,15 +119,18 @@ WNT_Window::WNT_Window (const Handle(WNT_GraphicDevice)& theDevice,
     dwStyle |= WS_CLIPCHILDREN;
   }
 
-  if (dwStyle & WS_OVERLAPPEDWINDOW)
-  {
-    // include decorations in the window dimensions
-    // to reproduce same behaviour of Xw_Window.
-    aXLeft   -= GetSystemMetrics(SM_CXSIZEFRAME);
-    aYTop    -= GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYCAPTION);
-    aXRight  += GetSystemMetrics(SM_CXSIZEFRAME);
-    aYBottom += GetSystemMetrics(SM_CYSIZEFRAME);
-  }
+  // include decorations in the window dimensions
+  // to reproduce same behaviour of Xw_Window.
+  RECT aRect;
+  aRect.top    = aYTop;
+  aRect.bottom = aYBottom;
+  aRect.left   = aXLeft;
+  aRect.right  = aXRight;
+  AdjustWindowRect (&aRect, dwStyle, theMenu != NULL ? TRUE : FALSE);
+  aXLeft   = aRect.left;
+  aYTop    = aRect.top;
+  aXRight  = aRect.right;
+  aYBottom = aRect.bottom;
 
   myHWindow = CreateWindow (
               myWClass->Name(),                 // window's class name
@@ -198,15 +201,18 @@ WNT_Window::WNT_Window (const Handle(WNT_GraphicDevice)& theDevice,
     dwStyle |= WS_CLIPCHILDREN;
   }
 
-  if (dwStyle & WS_OVERLAPPEDWINDOW)
-  {
-    // include decorations in the window dimensions
-    // to reproduce same behaviour of Xw_Window.
-    aXLeft   -= GetSystemMetrics(SM_CXSIZEFRAME);
-    aYTop    -= GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYCAPTION);
-    aXRight  += GetSystemMetrics(SM_CXSIZEFRAME);
-    aYBottom += GetSystemMetrics(SM_CYSIZEFRAME);
-  }
+  // include decorations in the window dimensions
+  // to reproduce same behaviour of Xw_Window.
+  RECT aRect;
+  aRect.top    = aYTop;
+  aRect.bottom = aYBottom;
+  aRect.left   = aXLeft;
+  aRect.right  = aXRight;
+  AdjustWindowRect (&aRect, dwStyle, theMenu != NULL ? TRUE : FALSE);
+  aXLeft   = aRect.left;
+  aYTop    = aRect.top;
+  aXRight  = aRect.right;
+  aYBottom = aRect.bottom;
 
   myHWindow = CreateWindow (
               myWClass->Name(),                 // window's class name