Create a main window for a game
In the previous tutorial, we have create a main window for a standard Windows application.
Now, we will make some changes to create a main window that can be used for a game view.
We define a structure called WindowDescriptor
that contains the information needed to create the game window.
The structure contains:
Title
– The title of the windowWidth
and Height
– The size of the windowMinWidth
and MinHeight
– The minimum size of the window (or 0 if unbounded)When we call the CreateWindowEx
function, we can replace the window title and the CW_USEDEFAULT
constant with values from the WindowDescriptor
structure.
HWND hWnd = CreateWindowEx(
WS_EX_OVERLAPPEDWINDOW,
wc.lpszClassName,
**WindowDescriptor.Title.c_str()**,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
**WindowDescriptor.Width**,
**WindowDescriptor.Height**,
nullptr,
nullptr,
hInstance,
nullptr);
The previous sample code creates a window that matches the specified window size.
However, the window contains a title bar and a border that reduce the client size of the window.
The Windows API distinguishes the client area and the nonclient area of a window. The client area is the rectangle where the game will be presented, and the nonclient area is the rectangle that includes the title bar, border, and other elements such as a menu menu if any is present.