Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As others stated AdjustWindowRect or AdjustWindowRectEx is the way to go. You need to do special handling if WS_VSCROLL or WS_HSCROLL is set. In my util library I also have special handling for WS_EX_STATICEDGE, but don't ask me where I got this information from (at least it's not in the MSDN documentation for AdjustWindowRect[Ex]).</p> <p>The bug in your latest test was that you are calling CreateWindow the wrong way, it takes a width and heigth, not right and bottom. This should work as required:</p> <pre><code>dwStyle = WS_OVERLAPPED | WS_THICKFRAME | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX; RECT r; r.left = 100; r.top = 100; r.right = 900; r.bottom = 700; BOOL result = AdjustWindowRect( &amp;r, dwStyle, FALSE ); hWindowHandle = CreateWindow( L"CGFramework", wszWndCaption, pWindowData-&gt;dwStyle, pWindowData-&gt;nPositionX, pWindowData-&gt;nPositionY, r.left, r.top, r.right-r.left, r.bottom-r.top, 0, 0, hInstance, 0 ); </code></pre> <p>And just for information, here is the complete sample:</p> <pre><code>#include "stdafx.h" #include &lt;Windows.h&gt; #include &lt;cstdio&gt; #include &lt;cassert&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; 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_CXSIZEFRAME )*2; //r.bottom = 600+GetSystemMetrics( SM_CYSIZEFRAME )*2+GetSystemMetrics( SM_CYCAPTION ); BOOL result = AdjustWindowRect( &amp;r, dwStyle, FALSE ); assert(result); char buffer[512]; sprintf( &amp;buffer[0], "adjust left=%i, top=%i, right=%i, bottom=%i", r.left, r.top, r.right, r.bottom ); MessageBoxA(0, buffer, 0, 0); HWND hWindowHandle = CreateWindow( L"CGFramework", L"Window Test", dwStyle, r.left, r.top, r.right-r.left, r.bottom-r.top, 0, 0, hInstance, 0 ); if( 0 == hWindowHandle ) { MessageBox(0, L"CreateWindow FAILED", 0, 0); UnregisterClass( wc.lpszClassName, hInstance ); return 0; } assert(GetWindowRect(hWindowHandle, &amp;r)); sprintf( &amp;buffer[0], "wnd left=%i, top=%i, right=%i, bottom=%i", r.left, r.top, r.right, r.bottom ); MessageBoxA(0, buffer, 0, 0); GetClientRect( hWindowHandle, &amp;r ); sprintf( &amp;buffer[0], "style=%08x/%08x, exstyle=%08x, left=%i, top=%i, right=%i, bottom=%i", GetWindowLong(hWindowHandle, GWL_STYLE), dwStyle, GetWindowLong(hWindowHandle, GWL_EXSTYLE), r.left, r.top, r.right, r.bottom ); MessageBoxA(0, buffer, 0, 0); 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); 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>
 

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