The Edit Control


The edit control window class is class "edit". By way of giving an example of usage of an edit control, the program of this section creates a simple text editor with 70 lines of code. Shown below is a snapshot of this tiny editor in action.

The client window procedure declares a variable editor and initializes it in the message message::create - as shown below.

result __stdcall client(handle window_handle,
                       unsigned identity,
                       parameter parameter1,
                       parameter parameter2)
{
 switch (identity)
  {
   case message::create:
    ...
    data->editor_handle = create_window(L"Edit",
                                style::child | style::visible | style::horizontal_scroll | style::vertical_scroll |
                                style::border | edit_style::left | edit_style::multiple_line |
                                edit_style::auto_scroll_horizontal | edit_style::auto_scroll_vertical,
                                IdentityEditor, window_handle);
    break;
    ...
  }
 return 0;
}

Various window styles are applied (including scroll bar styles) to the edit control, as well as a number of specific edit styles. The editor child window has identity IdentityEditor (==1) and the parent is the client window. When the client is receiving the focus, it sets the focus to the edit control, as shown below.

    case message::set_focus:
    {
        window_data* data = (window_data*)get_window_pointer(window_handle, 0);
        set_focus(data->editor_handle);
    }
    break;

When the client is sized, it sizes the child control with the following code.

    case message::size:
    {
        window_data* data = (window_data*)get_window_pointer(window_handle, 0);
        move_window(data->editor_handle, 0, 0, low_part(parameter2), high_part(parameter2), true);
    }
    break;

Edit Styles

By default, an edit control is single line. Typically, when using dialogs, the edit control acts as the primary means of textual input. When designing forms, single line edit fields are very useful when combined with the display (static) control. The display control provides the queues for data entry and the single line edit fields provide the actual means of data entry.

If a multiple line edit field is required, it may be explicitly specified via the style edit_style::multiple_line. If a multiple line edit field is being used, scroll bars may be added via the standard window styles style::horizontal_scroll and style::vertical_scroll. Automatic scrolling styles edit_style::auto_scroll_horizontal and edit_style::auto_scroll_vertical may be used to ensure that scrolling a multiple line edit field is automatic. For a multiple line edit field, if edit_style::auto_scroll_horizontal is not specified, text automatically word wraps.

By default, an edit control has no border. A border may be added with the standard style style::border. If a single line edit control has a border, its height should be set to 1.5 times the height of a single character (including external leading).

Notifications, Messages and Methods

An edit control notifies its parent of events via the message message::command. See edit notifications for details of these notifications. An edit control has a number of messages to which it responds. For a list of these, see edit messages.