Processing Button Click Commands
Introduction
Welcome back to Interactive Controls and Layouts. We are now in Lesson 3, and our small app already features a label, a text box, and a button. This marks significant progress at this stage of the course, as the window now resembles a functional interface rather than an empty frame.
In this lesson, we will make that interface respond to user actions. More specifically, we will handle the WM_COMMAND message, extract useful information from it, and detect when our Submit button is actually clicked. This is an important step because, once we can recognize a control event, we can start attaching real program behavior to it.
How A Button Reaches Our Code
A button does not execute our application logic on its own. In WinAPI, the button is a child control; when the user interacts with it, Windows sends a message to the parent window. For standard control actions, that message is typically WM_COMMAND.
The advantage is that WM_COMMAND does not merely indicate that something happened; it also carries details regarding which control sent the message and what type of event occurred. That is exactly what we need here. Our job is to read those details carefully so that we respond only to the correct control and the correct action.
Rebuilding The Interface In WM_CREATE
Before we can react to a click, the controls must first exist. Therefore, just as in the previous lessons, we begin inside WM_CREATE, where the window sets up its child controls.
The function begins with the familiar WindowProc signature and then switches on uMsg to determine what kind of message is being handled. Inside WM_CREATE, we retrieve the application instance with GetWindowLongPtr and then recreate the label and edit control from the earlier units. This keeps our interface complete: the label provides context, and the edit box provides a place to type. Even though this lesson focuses on button clicks, these controls still matter because they define the window with which we are interacting.
