Reading textboxes with Windows API

Posted on 2006-03-29
Medium Priority
Last Modified: 2013-12-03
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.
Question by:awptimus
LVL 86

Accepted Solution

jkr earned 375 total points
ID: 16328384
All you need to do is using 'WM_GETTEXT' - for an edit box, this will retrieve the text.
LVL 48

Expert Comment

ID: 16329930
Or use GetWindowText function.

Author Comment

ID: 16348174
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_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

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Screencast - Getting to Know the Pipeline
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question