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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve text from another window

Status
Not open for further replies.

LuckyLuke

Programmer
Mar 28, 2001
188
0
0
NL
Hi,

I'm working on a program and it recuires that I retrieve text from a label in another window. I have the label handle but I just can't seem to get the text. Just gettext and getwindowtext doesn't work. I asked another guy who already did such a thing once how he did it and he said something like: use settext first, then use gettext on the label you just used settext on. I don't quite get that lol.

I appreciate if you guys can answer my question.

LuCkY

 
Hi,

You can always use a property in your 2nd form to store the label's caption on the 1st form. Assign the label's caption on the 1st form into the public property of your 2nd form.

Have a good one!
BK
 
Hi again,

LOL, in case you didn't notice... I'm talking about another program... else API would be a big overacting wouldn't it ^^

LuCkY
 
Hi,

Oops...you said another window which isn't necessarily another program but I am sure you will learn to be more precise next time. <g> You could try using the clipboard.settext and clipboard.gettext functions. You can then transfer the label's caption to the other program.

Have a good one!
BK
 
Hi once again... ;)

OK, I'll try to explain some more detailled then... First of all, I think you NEED to do it with API...

Second of all, the other program isn't mine, so how on earth should I copy the contents of a lable to the clipboard???????

Its like this, its some sort of logger, it logs messages, inside a label, which pop up from another program, which is in NO way related to my program... So as soon as a message pops up, I want to retrieve the text from that message. I tried to do it with SENDMESSAGE(settext) and gettext lol, so not the clipboard version, which if its possible good also ;), and I tried a few other options. It didn't work out for me, so I contacted this guy who made a program just like mine. He said he used API too to do it, but he used the sendmessage, settext before he used gettext. Could anyone explain that to me or either give me a better version of how it is possible... I have the hWnd of the label. Suppose the hWnd is 1234, then could you guys please explain how to get the text...

LuCkY
 
My understanding was that labels were like graphical controls in that the win api doesn't consider them windows and thus have no handle. I'm not sure how you managed to get a handle for it. I sugest posting this on the Visual Basic Win32API forum.
 
misery347,
Remember that every control is essentially a Window as far as the OS is concerened. The fact that a label control can receive events is a good indication that it has a Window handle (even though VB doesn't expose it). It needs that handle to bind to the OS event queue. - Jeff Marler B-)
 
Not true. The line and shape controls are not windows. Also, The timer and common dialog controls have no windopw but can recive events. The label control itself can not recive focus and has no keyboard events. It would be an easy thing for VB to check if a mouse event occured in the area occupied by the label and generate an event.
 
misery347,
Hmmmm . . . OK . . . you're right! I just checked using SPY and the label uses the same event queue as the form. OH well . . . I typed before I thought :).
- Jeff Marler B-)
 
Whoops! I did something wrong (once again ;-)).

The thing is that the text I want to retrieve looks like a label, but it isn't a label. It is some sort of object (class = CStatic and it has its hWnd). The problem now is, how do I get the text? I know it can be done, because i've seen people do it before, but I just don't know how, all I know is that the author of that other program refused to tell it and all he wanted to tell me is use settext to the, *ahem*, label first, then use gettext (API) to retrieve the text.

Help me please! :) I'm so curious now! ;-)

LuCkY
 
I would keep the text of client area of a generic window of a generic application such Notepad, MsWord or remote terminal. There is some way to do this in vb? Thanks.
 
I had the same problem when trying to get the text out of a CStatic control on a MSN Zone Message dialog window. I had the hwnd of the window/control, but GetWindowText returned nothing as did sendmessage with WM_GETTEXT.

I'd be more than interested to find if anyone has a solution to this as I know it is possible in VB.
 
Clutching at straws and taking a guess off the top of my head: (And presuming you can Tab to this *label*)

Activate the *other* window. Use SendKeys to Tab to the label looking object. Try various sendkey combinations to select its text. Send the selection to the clipboard. Get the text from there.

Only an idea. X-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top