Link to home
Create AccountLog in
Avatar of awptimus
awptimus

asked on

Reading textboxes with Windows API

What is the appropriate method (probably using SendMessage) for reading a textbox when all you have is the hwnd?  I keep looking and all I can see are constants to set the text, not read.  I don't see an EM_GETTEXT constant anywhere.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of AlexFM
AlexFM

Or use GetWindowText function.
Avatar of awptimus

ASKER

Thanks JKR, I had tried it, but gave up when I didn't get the right result, but I tried again and it works just fine now.

This is the code I'm now using to get the text of the textbox
Public Function GetText(hwnd As Long) As String
    Const WM_GETTEXTLENGTH = &HE
    Const WM_GETTEXT = &HD
    Dim strTemp As String
    Dim lngLength As Long

    lngLength = SendMessage(hwnd, WM_GETTEXTLENGTH, ByVal 0, ByVal 0)

    strTemp = Space(lngLength)

    SendMessage hwnd, WM_GETTEXT, ByVal lngLength + 1, ByVal strTemp

    GetText = strTemp
End Function