Creating an Edit Control

An edit control, also called a text box, is a rectangular window in which a user can enter and edit text. Generally, you provide a label for an edit control by placing a static control with the appropriate text above or next to the edit control. However, if you do not have enough space, enclose the label within angle brackets—for example, <edit control label>—and include the enclosed label as the default text inside the edit control.

    To create an edit control using the CreateWindow function

  1. Specify the EDIT window class in the lpClassName parameter of the CreateWindow or CreateWindowEx function.
  2. Specify one or more edit control styles in the dwStyle parameter of the CreateWindow or CreateWindowEx function.

    The edit control style values you select can establish the appearance of a single-line or multiline edit control, align the text in the control, and determine if and how text appears in the edit control. The number and type of styles the application uses depend on the type and purpose of the edit control. For a complete listing of supported styles, see Window and Control Styles.

The following code example shows how to use CreateWindow to create an edit control.

#define EDITID 1

// Specify the edit control window style.
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | 
                WS_BORDER | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL | 
                ES_AUTOHSCROLL | ES_AUTOVSCROLL;  

// Create the edit control window.
g_hwndEdit = CreateWindow (
                TEXT("edit"),   // Class name
                NULL,           // Window text
                dwStyle,        // Window style
                0,              // x coordinate of the upper-left corner
                0,              // y coordinate of the upper-left corner
                CW_USEDEFAULT,  // Width of the edit control window
                CW_USEDEFAULT,  // Height of the edit control window
                hwnd,           // Window handle to parent window
                (HMENU) EDITID, // Control identifier
                g_hInst,        // Instance handle
                NULL);          // Specify NULL for this parameter when 
                                // creating a control

    To create an edit control in a dialog box

For a complete listing of supported styles, see Window and Control Styles.