Creating WinAPI Controls
Introduction
Welcome to Interactive Controls and Layouts. We are at the very beginning of the course, and this first lesson gives our window its first real interface elements. Instead of showing only an empty frame, we will add a text label and a button, which are two of the most common controls in desktop apps.
By the end of this lesson, we will know where these controls are created, why they are treated as windows themselves, and how WinAPI uses built-in system classes such as STATIC and BUTTON to place them inside a parent window.
Controls Are Also Windows
A helpful idea to keep in mind is this: in WinAPI, a control is usually just another window with a special purpose. A label is a window that displays text; a button is a window that reacts to clicks and keyboard focus. Because of that, we create them with the same family of functions used for regular windows.
The main difference is their role. These controls are created as child windows, which means they live inside the main window and depend on it. A very common place to create them is WM_CREATE because that message arrives when the parent window is being set up and is ready to receive its child controls.
Preparing The Window Procedure
Inside the source file that defines our window procedure, we begin by including WinAPI types, declaring control IDs, and opening the WM_CREATE branch. This sets up the space where the controls will be created.
There are three important pieces here. First, #include <windows.h> brings in the WinAPI declarations we need. Second, the #define values give each control a unique ID, which helps us recognize them later when handling events. Third, GetWindowLongPtr(hwnd, GWLP_HINSTANCE) fetches the application instance handle from the parent window, and that handle is passed into CreateWindowW when we build the child controls.
