Updating Interface Text
Introduction
Welcome back to Interactive Controls and Layouts. We have reached Lesson 4, which is a significant milestone in the course: our window already displays controls, accepts typed input, and responds to button clicks. Now, we will connect those components so the interface can transfer text from one control to another.
In this lesson, we will read the current text from an edit control and place that text into a static label when the button is clicked. This is a small feature, but it teaches a very important concept in GUI programming: interactive data flow inside the window procedure.
Entering The Setup Phase
The main logic still resides inside the window procedure. We begin the same way as before by checking which message arrived, then preparing the interface during WM_CREATE.
The function signature is the standard form for a WinAPI WindowProc. hwnd identifies the main window, and uMsg indicates which event Windows is reporting. When that message is WM_CREATE, the window is being set up for the first time. We also read the instance handle with GetWindowLongPtr because the child controls created in this branch require that GWLP_HINSTANCE value.
Building The Three Controls
Once we have the instance handle hInst, we create the label, the edit box, and the button. The layout is familiar, but several details now support the text update behavior we want.
The starting text L"Waiting for input..." makes the label appear active even before any typing occurs. The EDIT control begins empty, providing a blank space to type. The button text, L"Update Label", clearly describes the action. Most importantly, each control receives its own ID through HMENU, so the parent window can later locate the specific controls it needs using GetDlgItem.
