Showing the Beginning of an Edit Control after EM_SETSELLast reviewed: November 2, 1995Article ID: Q64758 |
The information in this article applies to:
SUMMARYIn a single-line edit control created with the ES_AUTOHSCROLL style, when the EM_SETSEL message is used to select the entire contents of the control, the text in the control is scrolled to the left and the caret is placed at the end of the text. This occurs when the control contains more text than can be displayed at one time. The order of the starting and ending positions specified in the lParam of the EM_SETSEL message makes no difference. If your application needs to have the entire contents selected and the beginning of the string in view, create the edit control using the ES_MULTILINE style. The order of the starting and ending positions in the EM_SETSEL message is respected by multiline edit controls.
MORE INFORMATIONConsider the following example, which sets and then selects the text in a single-line edit control created with the ES_AUTOHSCROLL style:
//hEdit and szText defined elsewhere SetWindowText(hEdit, szText); SendMessage(hEdit, EM_SETSEL, 0, MAKELONG(0x7FFF, 0));According to the documentation for the EM_SETSEL message, the low-order word of lParam specifies the starting position of the selection and the high-order word specifies the ending position. However, a single-line edit control ignores this ordering and always selects the text from the lower position to the higher position. If the content of the edit control is longer than the control can display, the text is scrolled to the end of the selection, and the caret is positioned there. In some situations, it is necessary to show the beginning of the text after the selection is made with EM_SETSEL. In Windows 3.00, there is no documented method to accomplish this positioning using a single-line edit control. A multiline edit control, sized to display only one line and created without the ES_AUTOVSCROLL style, will appear to the user as a single-line control. However, this control will respect the order of the start and end positions in the EM_SETSEL message. In the sample code above, a multiline edit control will select the text from the specified starting position to the specified ending position, regardless of which position is higher. In this example, the text is scrolled to the beginning and the caret is placed there. The beginning of the selected text is visible in the control. NOTE: A multiline edit control uses up slightly more memory in the USER heap than a single-line edit control.
|
Additional reference words: 3.00 3.10 3.50 3.51 4.00 95
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |