WinGetText and ControlGetText not working on certain windows

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TThomas
Posts: 6
Joined: 24 Feb 2017, 11:37

WinGetText and ControlGetText not working on certain windows

24 Feb 2017, 11:48

I try to get the text from win 8.1 popup windows but WinGetText and ControlGetText sometimes don't work at certain types of windows.

For example when closing Notepad, the text can not be extracted from the popup "Do you want to save changes to.." . This looks like a "PHANTOM WINDOW" the text is there but behaves like non existing. AU3_Spy shows as visible text only "&Save Do&n't Save Cancel" , these are the button texts but where is the rest of the text? AU3_Spy shows no hidden text.

Also noticed these problem windows have a horizontal line above the "&Save Do&n't Save Cancel" buttons.

The class name is alwys DirectUIHWND.

Can the text be extracted from such windows?

Does anybody know the solution?

Thanks
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: WinGetText and ControlGetText not working on certain windows

24 Feb 2017, 12:35

One way of doing it is by sending ^c to the dialog box - this will put the text into the clipboard.

My favourite way (this works for me on Explorer's extension change warning and on the MTP dialog box where it assumes my Android phone is a pre-TCPMP PocketPC and won't support whatever I'm copying to it) is using Acc.ahk. Download it and read this about the best place to put it (if you can't be bothered with that, just paste in Acc.ahk's contents at the end of your main script). Then do:

Code: Select all

text := Acc_Get("Name", "pane1.text1",, "ahk_id " . hwnd) 
MsgBox %text%
That assumes hwnd is a handle to a window of class DirectUIHWND(1). I did ControlGet hwnd, Hwnd,, DirectUIHWND1, Notepad ahk_class #32770 to get that window handle, but you presumably already have it. Try "dialogue1.window1.pane1.text1" if you're working directly on a window with class #32770 and if that doesn't work, try AccViewer on the dialog box to get the correct path.
TThomas
Posts: 6
Joined: 24 Feb 2017, 11:37

Re: WinGetText and ControlGetText not working on certain windows

24 Feb 2017, 18:17

Thanks for your reply. Solution 2 is not working. I write a program which monitors all kinds of popup windows. Finding the window handler to each and the controls is like finding a needle in the haystack.
However the simple sending CTRL-V does work, BUT interferes with the clipboard.

So before sending CTRL-V , I put the clipboard contents into a temporary variable. After sending CTRL-V put the content of the temp variable back into clipboard. That is fine

BUT

if the clipboard contains a file, not text, I lose the content of the clibboard.
For example I put picture.jpg into the clipboard, after the action can not paste picture.jpg anymore
the filename becomes a clipboard text. How can I fix it? Thanks
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: WinGetText and ControlGetText not working on certain windows

25 Feb 2017, 10:28

Here is a slight variation on the Acc technique shown above:

Code: Select all

q:: ;get text from Notepad save warning (tested on Windows 7)
;e.g. 'Do you want to save changes to C:\MyFile.txt?'
ControlGet, hCtl, Hwnd, , DirectUIHWND1, Notepad ahk_class #32770
oAcc := Acc_Get("Object", "4.1", 0, "ahk_id " hCtl)
vText := oAcc.accName(0)
oAcc := ""
MsgBox % vText
Return

;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
Btw:
Clipboard and ClipboardAll
https://autohotkey.com/docs/misc/Clipbo ... ipboardAll

Btw also:
I find AccViewer is the best tool to investigate windows, and iWB2 Learner is the best tool to investigate webpages on Internet Explorer windows, both available at:
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: WinGetText and ControlGetText not working on certain windows

28 Feb 2017, 06:59

You can also try the tools below, get what the text for the button is, and then write a script to do things with the button.

https://github.com/fincs/SciTE4AutoHotk ... owInfo.ahk
(Active Window Info)

https://sourceforge.net/projects/winspy ... t/download
(WinSpy)

There is also different commands in ControlGet that can help.

ControlGet, ControlSee1, Visible,, Button1, WhateverWindow

You can check if the control is visible, then get a 0 or 1 to your variable (ControlSee1). You can do the same trick for if the button is enabled or not, getting a 0 or 1 to your variable.

if (ControlSee1 = "1")
ControlClick, Button1, WhateverWindow, , Left, 1, NA,

Just saying, there can be alternative ways to do something.
polinei

Re: WinGetText and ControlGetText not working on certain windows

30 Aug 2018, 07:59

thanks for jeeezwg !! can you explain what the 4 is for? it works but would like to know

in example ("Object", "4.1", 0, "ahk_id " hCtl) I do not see 4 when i use acc viewer
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: WinGetText and ControlGetText not working on certain windows

30 Aug 2018, 12:54

- Acc gets the 4th child item, then the 1st child item.
- Sometimes I use Acc to put the focus rectangle around the entire window or a control, and then manually go through the treeview, to retrieve numbers.
- An alternative is to get the numbers for all GUI elements:
Acc: get text from all window/control elements - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=40615
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
ritilde

Re: WinGetText and ControlGetText not working on certain windows

30 Aug 2018, 18:31

jeeswg wrote:- Acc gets the 4th child item, then the 1st child item.
- Sometimes I use Acc to put the focus rectangle around the entire window or a control, and then manually go through the treeview, to retrieve numbers.
- An alternative is to get the numbers for all GUI elements:
Acc: get text from all window/control elements - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=40615
thanks for that reply

I just output a list of a program i have and it says one object is located at
4.9.1 c3

How do I enter that? I tried

3.4.9.1

I tried 4.9.1.3

but gettiing blanks
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: WinGetText and ControlGetText not working on certain windows

30 Aug 2018, 19:13

Something like this:

Code: Select all

oAcc := Acc_Get("Object", "4.9.1", 0, "ahk_id " hWnd)
MsgBox, % oAcc.accName(3)
MsgBox, % oAcc.accValue(3)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
ritilde

Re: WinGetText and ControlGetText not working on certain windows

30 Aug 2018, 19:48

jeeswg wrote:Something like this:

Code: Select all

oAcc := Acc_Get("Object", "4.9.1", 0, "ahk_id " hWnd)
MsgBox, % oAcc.accName(3)
MsgBox, % oAcc.accValue(3)
that did it thank u so very much

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Askeron52, Google [Bot] and 123 guests