Page 1 of 1

ControlGetText Issues

Posted: 06 Jan 2018, 20:16
by SOTE
Have been having a number of scripts stop working for some updated applications, and it appears that ControlGetText is not getting info from the control name anymore. Not sure if it's also an issue with the latest version of AutoHotkey. I would do a simple test script using ControlGetText and Msgbox, to see what's happening. Getting back blank in the Msgbox.

It's odd, as in WindowSpy.ahk can see the text on the control, but not test scripts that I make. As a workaround, I'm using WinGetText. That command will often find the text I'm looking for, and then IfInString or InStr can be used.

1) Has anybody else been having issues lately with ContolGetText?

2) What are reasons why AutoHotkey may not be able to get text from a control?

3) Can anyone suggest some other methods that can be tried to get text from a control?

Re: ControlGetText Issues

Posted: 06 Jan 2018, 20:33
by Haxt0r Baxtor
SOTE wrote:Have been having a number of scripts stop working for some updated applications, and it appears that ControlGetText is not getting info from the control name anymore. Not sure if it's also an issue with the latest version of AutoHotkey. I would do a simple test script using ControlGetText and Msgbox, to see what's happening. Getting back blank in the Msgbox.

It's odd, as in WindowSpy.ahk can see the text on the control, but not test scripts that I make. As a workaround, I'm using WinGetText. That command will often find the text I'm looking for, and then IfInString or InStr can be used.

1) Has anybody else been having issues lately with ContolGetText?

2) What are reasons why AutoHotkey may not be able to get text from a control?

3) Can anyone suggest some other methods that can be tried to get text from a control?
double check the control names they do change sometimes, some programs button1 can turn into button2

Re: ControlGetText Issues

Posted: 06 Jan 2018, 22:08
by SOTE
Haxt0r Baxtor wrote: double check the control names they do change sometimes, some programs button1 can turn into button2
True, when some programs are updated, they do change the button numbers. Thus ControlSend or Postmessage can help with that.

However, I checked for this. When I do the test script, I put the button name as reported by WindowSpy.ahk or other scripts that are similar.
Example-

Code: Select all

ControlGetText, ShowTheText, BUTTON2, Title Of Windows Program
The test script can't pull the text from the control, in various programs.

Re: ControlGetText Issues

Posted: 07 Jan 2018, 02:30
by Haxt0r Baxtor
SOTE wrote:
Haxt0r Baxtor wrote: double check the control names they do change sometimes, some programs button1 can turn into button2
True, when some programs are updated, they do change the button numbers. Thus ControlSend or Postmessage can help with that.

However, I checked for this. When I do the test script, I put the button name as reported by WindowSpy.ahk or other scripts that are similar.
Example-

Code: Select all

ControlGetText, ShowTheText, BUTTON2, Title Of Windows Program
The test script can't pull the text from the control, in various programs.
try running your script as admin and also remember that programs can block you from pulling text

Re: ControlGetText Issues

Posted: 13 Jan 2018, 21:01
by SOTE
Haxt0r Baxtor wrote:
SOTE wrote:
Haxt0r Baxtor wrote: double check the control names they do change sometimes, some programs button1 can turn into button2
True, when some programs are updated, they do change the button numbers. Thus ControlSend or Postmessage can help with that.

However, I checked for this. When I do the test script, I put the button name as reported by WindowSpy.ahk or other scripts that are similar.
Example-

Code: Select all

ControlGetText, ShowTheText, BUTTON2, Title Of Windows Program
The test script can't pull the text from the control, in various programs.
try running your script as admin and also remember that programs can block you from pulling text
Yes, I did run the program as administrator. Possibly might be problems with the version of AutoHotkey used. There seems to be a difference in behavior.

Re: ControlGetText Issues

Posted: 14 Jan 2018, 02:21
by scriptor2016
does this make any difference?

Code: Select all

ControlGetText, ShowTheText, Static1, Title Of Windows Program ;change Static1 to whichever the button is such as Static2, or Static3, etc

Re: ControlGetText Issues

Posted: 06 Dec 2018, 22:41
by SAbboushi
Haxt0r Baxtor wrote:
07 Jan 2018, 02:30
... programs can block you from pulling text
I'm having a similar problem: Works on some controls but not on others. Would seem odd that the program is intentionally blocking the text (UltraSearch, ClassNN = "TButtonedEdit1"; works fine on the other controls in that window). Any thoughts on how to diagnose/workaround? Could it be the difference between a Standard windows control vs. a custom control and if so, how can one tell the type of control used? Style of "TButtonedEdit1": 0x000000C0, WS_CHILD, WS_CLIPSIBLINGS, WS_TABSTOP, WS_VISIBLE

WindowSpy.ahk doesn't retrieve the text either, but AutoIt Control Viewer does. Wonder how their tool is doing it??

Re: ControlGetText Issues

Posted: 06 Dec 2018, 23:15
by CyL0N
Try ControlClickByControlText(), If the button has exposed text, it'll find it, else it's probably either a custom control(subcontrol),...

@SAbboushi
Most likely that uses Acc or something like that to get the control text....

Re: ControlGetText Issues

Posted: 07 Dec 2018, 00:45
by SAbboushi
Thanks CyLON. I tried your script but didn't get a result (including for controls that ControlGetText() work on. Maybe I'm doing something wrong (I didn't know what to use for searchStr):

Code: Select all

ControlClickByControlText(searchStr, controlName:="TButtonedEdit1", winTitle:="UltraSearch",passes:=1)
I tried sending a message hoping that would work, but no joy (I thought sending a message is supposed to work for custom controls?). result = "" and ErrorLevel = 1. Works fine for other controls:

Code: Select all

	buffer_size := 20
	
	; ensure AHk properly updates variable by initializing with non-zero value
	VarSetCapacity( buffer, buffer_size, 1 )

/*	
	WM_GETTEXT 	wParam = (WPARAM) cchTextMax; 
				lParam = (LPARAM) lpszText;
	
	Parameters:
	
	cchTextMax
	Specifies the maximum number of characters to be copied, including the terminating null character.
	
	lpszText
	Long pointer to the buffer that is to receive the text.
	
	Return Values
	The return value is the number of characters copied.
*/
	
	result:=SendMessage( 0xD, buffer_size, &buffer, "TButtonedEdit1", AppWinTitle ) ; 0xD = WM_GETTEXT
WinGetText( AppWinTitle ) shows the text.
CyL0N wrote:
06 Dec 2018, 23:15
Most likely that uses Acc...
What's Acc?

Re: ControlGetText Issues

Posted: 07 Dec 2018, 09:02
by CyL0N
SAbboushi wrote:
07 Dec 2018, 00:45
Thanks CyLON. I tried your script but didn't get a result (including for controls that ControlGetText() work on. Maybe I'm doing something wrong (I didn't know what to use for searchStr):

Code: Select all

ControlClickByControlText(searchStr, controlName:="TButtonedEdit1", winTitle:="UltraSearch",passes:=1)
I tried sending a message hoping that would work, but no joy (I thought sending a message is supposed to work for custom controls?). result = "" and ErrorLevel = 1. Works fine for other controls:

Code: Select all

	buffer_size := 20
	
	; ensure AHk properly updates variable by initializing with non-zero value
	VarSetCapacity( buffer, buffer_size, 1 )

/*	
	WM_GETTEXT 	wParam = (WPARAM) cchTextMax; 
				lParam = (LPARAM) lpszText;
	
	Parameters:
	
	cchTextMax
	Specifies the maximum number of characters to be copied, including the terminating null character.
	
	lpszText
	Long pointer to the buffer that is to receive the text.
	
	Return Values
	The return value is the number of characters copied.
*/
	
	result:=SendMessage( 0xD, buffer_size, &buffer, "TButtonedEdit1", AppWinTitle ) ; 0xD = WM_GETTEXT
WinGetText( AppWinTitle ) shows the text.
CyL0N wrote:
06 Dec 2018, 23:15
Most likely that uses Acc...
What's Acc?


ACC:
https://autohotkey.com/boards/viewtopic.php?t=26201


Search String is the control the text(button text for example(ok,cancel,...)) on the control,It's what the function searches for.

I Suggested my function as a solution so that @SOTE can test if the control does have an active text,that is somehow hidden underneath another control.... If the control doesn't respond to an attempt by the function,then the control text is most likely inside a custom control.....

Re: ControlGetText Issues

Posted: 07 Dec 2018, 10:25
by sinkfaze
Run this code (fill in the window title as indicated) and tell me if the text of the control that you're looking for shows up in the list:

Code: Select all

WinGet, cList, ControlList, << your window title here >>
Loop, Parse, cList, `n, `r
{
	ControlGetText, t, %A_LoopField%, << your window title here >>
	out .=	A_LoopField ":`t`t" t
}
MsgBox %	t
return

Re: ControlGetText Issues

Posted: 07 Dec 2018, 12:12
by SAbboushi
Thanks sinkfaze: the control is listed, but no text. Just to clarify, this control is / appears to be an edit box. The only unusual (visible) aspect is that when I type text into the box, a warning icon overlaps the right edge of the box (to warn that searching for text is a slow process). Note that the icon (size/position) does not overlap the text:
Image (Edit: don't know why this image isn't displaying... try https://1drv.ms/u/s!AoxenOc43-zegZNFoNwRO2e_OSAnLw)

For anyone else that wants to use sinkfaze's script, modify a couple lines:

Code: Select all

out .=	A_LoopField ":`t`t" t "`n"
}
MsgBox %	out
CyL0N wrote:
07 Dec 2018, 09:02
...Search String is the control the text(button text for example(ok,cancel,...)) on the control,It's what the function searches for ...
So since this control is an edit box, I should set Search String to be the text that I've typed into the edit box?
CyL0N wrote:
07 Dec 2018, 09:02
...hidden underneath another control...
Just to make sure I understand:
1) if one control is above another, then a spy utility might not be able to retrieve e.g. text from a control that is overlapped by another?
2) if I'm using ControlGetText() and specifying the control's ClassNN or HWND, then I suspect it wouldn't matter whether the control is overlapped or not?

CyL0N wrote:
07 Dec 2018, 09:02
... If the control doesn't respond to an attempt by the function,then the control text is most likely inside a custom control.....
3) So the link I posted above seems to be incorrect:

Re: ControlGetText Issues

Posted: 07 Dec 2018, 12:15
by SAbboushi
CyLON: I entered "asdf" into the edit box and tried:

Code: Select all

ControlClickByControlText(searchStr:="asdf", controlName:="TButtonedEdit1", winTitle:="UltraSearch",passes:=1)
Your script didn't respond with anything...

Re: ControlGetText Issues

Posted: 07 Dec 2018, 12:50
by SAbboushi
I'm thinking this control is not a standard Windows Control and might be this: TButtonedEdit_(Delphi)

Can anyone make sense of this and suggest whether or not I can get/set the text in this control from within AHK?