Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinAPI: Create a window with a specified client area size

I was wondering how can I create a window using Win32 API with a specific client area size.

When trying to create a window using the following piece of code, the entire window is 640x480, with the window's chrome taking some of the client area:

HWND       hWnd; WNDCLASSEX WndClsEx; ZeroMemory(&WndClsEx, sizeof(WNDCLASSEX));  WndClsEx.cbSize        = sizeof(WNDCLASSEX); WndClsEx.style         = CS_HREDRAW | CS_VREDRAW; WndClsEx.lpfnWndProc   = DefWindowProc; WndClsEx.cbClsExtra    = 0; WndClsEx.cbWndExtra    = 0; WndClsEx.hIcon         = LoadIcon(NULL, IDI_APPLICATION); WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW); WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); WndClsEx.lpszMenuName  = NULL; WndClsEx.lpszClassName = TEXT("Title"); WndClsEx.hInstance     = hInstance; WndClsEx.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);  RegisterClassEx(&WndClsEx);  hWnd = CreateWindowEx(  NULL,             TEXT("Title"),             TEXT("Title"),             WS_OVERLAPPEDWINDOW,             CW_USEDEFAULT,             CW_USEDEFAULT,             640,             480,             NULL,             NULL,             hInstance,             NULL); 

Assuming simple math won't quite solve the problem, how do I take the chrome size into account?

Note: I'm using SDL after creating the window, but I'm guessing it's bound to the window size and makes no difference to its size.

like image 605
GeReV Avatar asked Jan 30 '11 15:01

GeReV


People also ask

What is client area of a window?

The client area is the part of the window which can contain controls. It excludes the window's title bar, menu (if it has a standard one) and borders. The position and size of the client area are less dependent on OS version and theme than the values returned by WinGetPos.

What is Getclientrect?

Retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0).


1 Answers

You can use the AdjustWindowRect or AdjustWindowRectEx function to calculate the window size given a desired client area size.

like image 68
Ferruccio Avatar answered Oct 05 '22 16:10

Ferruccio