Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get text from an object

Status
Not open for further replies.

LuckyLuke

Programmer
Mar 28, 2001
188
NL
Hi,

I have the hWnd and the Class from an unknown object. The class is CStatic.

The object is looks like a simple lable. I want to retrieve the text which is inside and I've already tried a few things like gettext and getwindowtext. Either I'm doing it wrong or I'm trying it with the wrong commands. I know this can be done, because I've seen someone else do it.

Please help,

Thanks in advance,

LuCkY
 
If you can reference this object simply use the property carry this lable, some thing like
Dim x as string
X=MyObject.whatever_property_hold_the_lable

If you made an early binding to your object, the dot operator will give you a drop down list of all the properties and methods for this object, try to make a good guess of you don't know which one to use.
Good luck Walid Magd
Engwam@Hotmail.com
 
Hi again,

Lol, I seem never to explain good enough whats going on. Obviously (atleast, I think its obvious), this object is in another program. Why else would I write it down in the API forum ^^

LuCkY
 
Never mind, I found the solution to it... Thanks anyways.

LuCkY
 
All the world is waiting. What did you find?

I looked at the problem and muttered, "How the !@#$ would I do that?"
VCA.gif

Alt255@Vorpalcom.Intranets.com​
 
Hi,

Well I dled a program which had a sort of Spy on it. I thought, what the heck, lets try it and it actually got the text out of the object. I was amazed and searched for the sourcecode on that side but couldn't find it. I found another program from him which had that code in it though and he had 2 different ways in his program to get text. Appearantly he had the same problem as me once. First he does it with getwindowtext. If there is no result he does it with sendmessage, WM_GETTEXT. Somehow it gets the result with the 2nd one, which I think is very odd, cuz I've tried that several times...

Anyway, the code is just as simple as this:

Private Function GetText(hWnd As Long) As String
Dim sBuffer As String, lLength As Long

sBuffer = Space(255)
lLength = SendMessage(hWnd, WM_GETTEXT, 255, ByVal sBuffer)
sBuffer = Left(sBuffer, lLength)

GetText = sBuffer
End Function

LuCkY
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top