Note that there are some explanatory texts on larger screens.

plurals
  1. POVisual Studio 2012 app window creation/resizing differ from VS2008 window creation? Why?
    primarykey
    data
    text
    <p>@EDIT: I found out that it seems to be an issue of the Windows 8 RC, because I tried with Windows 7 and VS 2012, both classic and Aero view and it works fine. Thanks to @Werner Henze and @Ven Boigt for their feedback</p> <p>EDIT 2: Turns out this was a bug in Windows due to being beta and it was fixed in newer revisions so I don't have to worry about this anymore. Thanks for the feedback anyway.</p> <p>I used to do the following to create a window of an 800*600 client area:</p> <pre><code>dwStyle = WS_OVERLAPPED | WS_THICKFRAME | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX; hWindowHandle = CreateWindow( L"CGFramework", wszWndCaption, pWindowData-&gt;dwStyle, pWindowData-&gt;nPositionX, pWindowData-&gt;nPositionY, 800 + GetSystemMetrics( SM_CXSIZEFRAME )*2, 600 + GetSystemMetrics( SM_CYSIZEFRAME ) *2 + GetSystemMetrics( SM_CYCAPTION ), 0, 0, hInstance, 0 ); </code></pre> <p>Then when querying the client rect with GetClientRect, I used to get 800*600, but now I upgraded my Visual Studio 2008 project to VS2012, and now the GetClientRect() function is returning 792*592 instead. </p> <p>On top of that, the actual size of the window being created is 804*629, for which I see no reason as the resizeable frame (from WS_THICKFRAME) is obviously larger than 2 pixels on each side.</p> <p>I thought it was an issue of the Aero behaviour of Windows 8, but then I realized this is only happening with my VS2012 builds and not with my VS2008 builds. It makes no difference if I run it on Aero or the classic style, the behaviour will only apply to VS2012 builds. Why? Is there something I can change on my VS2012 project configuration to fix this horrible behaviour?</p> <p>I tried changing "DPI Awareness" setting of the project config, but this is not making any difference. I also removed the use of manifest in the same config page, still don't see any change in the resulting window.</p> <p>this is my test code:</p> <pre><code>#include &lt;Windows.h&gt; #include &lt;cstdio&gt; LRESULT CALLBACK MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch( uMsg ) { // WM_DESTROY is sent when the window is being destroyed. case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc( hWnd, uMsg, wParam, lParam ); } } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nShowCmd ) { WNDCLASS wc; wc.style = NULL; // CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = MainWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(0, IDI_APPLICATION); wc.hCursor = LoadCursor(0, IDC_ARROW); wc.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_3DFACE)); wc.lpszMenuName = 0; wc.lpszClassName = L"CGFramework"; DWORD dwStyle = WS_OVERLAPPED | WS_THICKFRAME | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX; // WS_DLGFRAME | if( !RegisterClass(&amp;wc) ) { MessageBox(0, L"RegisterClass FAILED", 0, 0); return E_FAIL; } RECT r; //r.left = 100; //r.top = 100; //r.right = 800; //r.bottom = 600; ////----------------------------- r.left = 100; r.top = 100; r.right = 900; r.bottom = 700; ////----------------------------- //r.left = 100; //r.top = 100; //r.right = 800+GetSystemMetrics( SM_CXFRAME )*2; //r.bottom = 600+GetSystemMetrics( SM_CYFRAME )*2+GetSystemMetrics( SM_CYCAPTION ); BOOL result = AdjustWindowRect( &amp;r, dwStyle, FALSE ); HWND hWindowHandle = CreateWindow( L"CGFramework", L"testWindow", dwStyle, r.left, r.top, r.right-r.left, r.bottom-r.top, // r.left, r.top, r.right, r.bottom, 0, 0, hInstance, 0 ); if( 0 == hWindowHandle ) { MessageBox(0, L"CreateWindow FAILED", 0, 0); UnregisterClass( wc.lpszClassName, hInstance ); return 0; } char buffer[512]; // for outing test message GetClientRect( hWindowHandle, &amp;r ); sprintf( &amp;buffer[0], "left=%i, top=%i, right=%i, bottom=%i", r.left, r.top, r.right, r.bottom ); MessageBoxA(0, buffer, 0, 0); // print rect values before ShowWindow ShowWindow( hWindowHandle, SW_SHOW ); GetClientRect( hWindowHandle, &amp;r ); sprintf( &amp;buffer[0], "left=%i, top=%i, right=%i, bottom=%i", r.left, r.top, r.right, r.bottom ); MessageBoxA(0, buffer, 0, 0); // print rect values after ShowWindow // main window loop MSG msg; ZeroMemory( &amp;msg, sizeof( MSG ) ); while( msg.message != WM_QUIT ) { while( PeekMessage( &amp;msg, 0, 0, 0, PM_REMOVE ) ) { TranslateMessage( &amp;msg ); DispatchMessage( &amp;msg ); } if( GetAsyncKeyState( VK_ESCAPE ) ) DestroyWindow( hWindowHandle ); } UnregisterClass( wc.lpszClassName, hInstance ); return 0; } </code></pre> <p>Please watch carefullly the code before answering as you may end up answering something I already tried (I'm posting this question because I already wasted all my choices).</p> <p>I'm using Windows 8 RC (MS windows 6.2.8400) and VS2012 RC (11.0.50706.0 QRELRC July 2012) to get this weird behaviour and none of the kind answers were able to address this issue. Be sure of reading them and testing my code before making any assumptions, as this code has been tested in many ways with subtle differences which in the end provided no improvement.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload