Hi
I am trying to retrieve text associated with a control using the handle of that control. In the code below, res1 returns some valid text. However, res2 returns the value of ##NOSUCHOBJECT## instead of the same text as returned by res1. Any clues as to what I am doing wrong?
Let>WIN_USEHANDLE=0
GetControlText>XYZ,TCheckBox,1,res1
Let>WIN_USEHANDLE=1
//TCheckBox instance 1 has the focus
GetFocusedObject>hwnd
GetControlText>hwnd,TCheckBox,1,res2
Regards
Athol
Retrieving text using a control handle
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
GetFocusedObject is an undocumented function provided for a specific client, so I'm guessing Athol must be from that organisation.
GetControlText requires a window name and a class name of a child object within that window. The window name must be a parent window. What you're doing is passing in the actual object handle instead of its parent window handle. Hence the difference.
If you have the handle from GetFocusedObject and want to get that object's text use the API function GetWindowText via LibFunc to retrieve the text given the handle. E.g.
That will return the caption text of the focused object, depending on the object in question and whether or not it published a caption property (if you get nothing back it is down to the control and not me).
Now that this has been outed, for everyone else's benefit, GetFocusedObject simply returns the handle of whatever object currently has the focus. I was planning to blog it at some point as a "bonus" function. It was being held over for official release in the next version. At present it is not included in the docs or the code builder, but if you type it into the editor you'll see it is recognised by the syntax highlighter and it also works in the current version! Enjoy.
GetControlText requires a window name and a class name of a child object within that window. The window name must be a parent window. What you're doing is passing in the actual object handle instead of its parent window handle. Hence the difference.
If you have the handle from GetFocusedObject and want to get that object's text use the API function GetWindowText via LibFunc to retrieve the text given the handle. E.g.
Code: Select all
GetFocusedObject>hwnd
LibFunc>user32,GetWindowTextA,gwaRes,hwnd,str,255
MidStr>gwaRes_2,1,gwaRes,theText
MessageModal>theText
Now that this has been outed, for everyone else's benefit, GetFocusedObject simply returns the handle of whatever object currently has the focus. I was planning to blog it at some point as a "bonus" function. It was being held over for official release in the next version. At present it is not included in the docs or the code builder, but if you type it into the editor you'll see it is recognised by the syntax highlighter and it also works in the current version! Enjoy.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Looking forward to the blog post for examples of usage... and thanks Marcus for this early Christmas bonus.mtettmar wrote:GetFocusedObject is an undocumented function...
I was planning to blog it at some point as a "bonus" function. It was being held over for official release in the next version. At present it is not included in the docs or the code builder, but if you type it into the editor you'll see it is recognised by the syntax highlighter and it also works in the current version! Enjoy.

jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

GetControlText mismatch
Hello,
Can someone tell me if the function GetControlText works in virtual environment, such as remote desktops?
I am using the function to get the text within a ThunderRT6TextBox in a VB6-based form.
Code snippet:
Label>Check_Retry
WIN_USEHANDLE=1
GetControlText>HWND_Form,ThunderRT6TextBox,9,controlTxt
If>controlTxt=##NOSUCHOBJECT##,Check_Retry
The macro worked well before in live environment but seems to go into an eternal loop in the virtual environment during testing due to GetControlText always returning ##NOSUCHOBJECT## despite the class and instance number being correct.
Any suggestions appreciated.
Can someone tell me if the function GetControlText works in virtual environment, such as remote desktops?
I am using the function to get the text within a ThunderRT6TextBox in a VB6-based form.
Code snippet:
Label>Check_Retry
WIN_USEHANDLE=1
GetControlText>HWND_Form,ThunderRT6TextBox,9,controlTxt
If>controlTxt=##NOSUCHOBJECT##,Check_Retry
The macro worked well before in live environment but seems to go into an eternal loop in the virtual environment during testing due to GetControlText always returning ##NOSUCHOBJECT## despite the class and instance number being correct.
Any suggestions appreciated.
