The EM_GETSEL message identifies what text is currently selected in an edit control. The message effectively gives the character positions of the beginning and end of the selection.
The message returns the start and end positions of the text selection, packed into a single 32-bit integer. The low-order word contains the starting position of the selection and the high-order word contains the position of the first character after the selection. However, it is easier to use the values placed into wParam and lParam to read the selection instead of using the return value.
None.
Const EM_GETSEL = &HB0
' 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_GETSEL = &HB0
' Display the selected text in edit control Text1. This is done by sending messages
' to get the selection, and then accessing the control's .Text property to read its contents.
Dim startpos As Long ' starting position of the selection
Dim endpos As Long ' ending position of the selection
Dim retval As Long ' return value
Dim seltext As String ' the selected text
' Figure out where the selection in Text1 is.
retval = SendMessage(Text1.hWnd, EM_GETSEL, startpos, endpos)
' Now isolate that selection from the entire text and display it.
If startpos <> endpos Then
seltext = Mid(Text1.Text, startpos + 1, endpos - startpos)
Debug.Print "Text selection: "; seltext
Else
Debug.Print "No selection."
End If
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_getsel.html