EM_SETSEL Message

Platforms

Description & Usage

The EM_SETSEL message changes the current text selection inside an edit control. Once this message sets the selection, the edit control's caret is placed immediately at the end of the selection.

Return Value

This message does not return a meaningful value.

Visual Basic-Specific Issues

None.

Parameters

wParam
The zero-based position of the first character in the selection. If this is -1, no text is selected.
lParam
The zero-based position of the first character that appears immediately after the end of the selection. In other words, this is one plus the position of the last selected character. If this is -1, the selection extends to the end of the control.

Constant Definitions

Const EM_SETSEL = &HB1

Example

' This code is licensed according to the terms and conditions listed here.

' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd _
	As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
Public Const EM_REPLACESEL = &HC2
Public Const EM_SETSEL = &HB1

' Select the first five characters in edit control Text1.  Then replace the newly
' selected text with the words "REPLACEMENT TEXT".
Dim retval As Long  ' return value

' First, select the first five characters of Text1.
retval = SendMessage(Text1.hWnd, EM_SETSEL, ByVal CLng(0), ByVal CLng(5))
' Then replace the selection with some other text.  Allow the user to undo it.
retval = SendMessage(Text1.hWnd, EM_REPLACESEL, ByVal CLng(1), ByVal "REPLACEMENT TEXT")

See Also

EM_GETSEL, EM_REPLACESEL

Category

Edit Controls

Back to the Message list.
Back to the Reference section.


Last Modified: May 21, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/e/em_setsel.html