In Windows, the width and height of the Win32 window are determined when the window is created. If the size we set is only the customer area of the window (like a common Direct3D window Program), the accepted size is the size of the entire window because the CreateWindow is called directly, this will make the actual customer region smaller than we imagined. This is because in addition to the customer area, the actual window may also contain borders and title bars. This part actually occupies space, which causes the customer area to be compressed.
To accurately create the size of the customer area, you must calculate the size of the window containing the border and title bar before passing it to CreateWindow.
1 DWORD window_style;
2 // specify that the created window contains the title bar and border (WS_CAPTION itself contains WS_BORDER)
3 // in reality, it is found that there is no difference even if WS_CAPTION is not specified.
4 window_style = WS_SYSMENU | WS_CAPTION;
5
6 // create a window with a size of 100,100*512 in (512)
7 int x = 100, y = 100;
8 int width = 512, height = 512;
9
10 // calculate the final window size
11 RECT window_rect;
12 SetRect (& window_rect, x, y, x + width, y + height );
13 AdjustWindowRect (& window_rect, window_style, FALSE );
Pass window_rect returned by AdjustWindowRecet to CreateWindow to create a correct window.