Read Text From Windows Confirmation Dialog?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Read Text From Windows Confirmation Dialog?

03 Mar 2020, 11:53

I'm trying to do something that seems like it should be simple, and it proving frustratingly difficult. I am trying to detect the following popup, and click "no" when that popup - and ONLY that exact popup with that exact text - appears.

Unfortunately, WindowSpy does not seem to be able to detect the text associated with an ahk_class TMessageForm dialog.

Here is the prompt:
Popup.png
Popup.png (6.82 KiB) Viewed 932 times
Here is what WindowSpy says about the prompt:
Wspy.png
Wspy.png (24.49 KiB) Viewed 932 times
And here is some code that does NOT work:

Code: Select all

^k::
	IfWinExist, Confirmation, Do you want to update the promo at all locations?
		MsgBox % "Victory is mine!"
	else
		MsgBox % "Sad panda noises."
	return
This results in sad panda noises. If I match only to the WinTitle, Confirmation, it works, but then it triggers for every Windows confirmation dialog, not just the one I want to target.

Any ideas?
Rohwedder
Posts: 7627
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Read Text From Windows Confirmation Dialog?

03 Mar 2020, 12:26

Hallo,
perhaps ???

Code: Select all

^k::
IF WinExist("Confirmation ahk_exe Product.exe")
{
	WinGetPos,,, Width, Height
	IF (Width = 347 And Height = 136)
		MsgBox, click No
}
Return
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: Read Text From Windows Confirmation Dialog?

03 Mar 2020, 12:36

Unfortunately there are other confirmation dialogs generated by the same program that I need to avoid clicking on.
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: Read Text From Windows Confirmation Dialog?

03 Mar 2020, 12:47

Try this:

Code: Select all

Global Criteria := "Confirmation ahk_class TMessageForm ahk_exe Product.exe"

Gui +LastFound
DllCall("RegisterShellHookWindow", "Ptr", WinExist())
OnMessage(DllCall("RegisterWindowMessage", "Str", "SHELLHOOK"), "OnShellMessage")
 
OnShellMessage(wParam, lParam) {
    If (wParam == 1) { ; HSHELL_WINDOWCREATED
        If (WinExist(Criteria . " ahk_id" . lParam)) {
            ;MsgBox Popup detected.
            ControlClick, &No, ahk_id %lParam%
        }
    }
}
You may need to provide more identification criteria in order to distinguish this popup from others of the same application. Isn't there a way to retrieve the text?
wineguy
Posts: 10
Joined: 03 Dec 2019, 16:26

Re: Read Text From Windows Confirmation Dialog?

03 Mar 2020, 16:10

If you can't get text normally you could try using the awesome OCR function by @malcev, whenever you detect a popup (see post #15 for coord mode lookup syntax). It's quite fast!
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=72674
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: Read Text From Windows Confirmation Dialog?

03 Mar 2020, 16:33

Alguimist wrote:
03 Mar 2020, 12:47
You may need to provide more identification criteria in order to distinguish this popup from others of the same application. Isn't there a way to retrieve the text?
As I said in my first post, the entire problem is that I can't figure out a way to retrieve the text. :)
wineguy wrote:
03 Mar 2020, 16:10
If you can't get text normally you could try using the awesome OCR function by @malcev, whenever you detect a popup (see post #15 for coord mode lookup syntax). It's quite fast!
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=72674
Thank you, I will check that out. I'd like to avoid using OCR if possible as it's fairly janky in my experience, but if there's no other way...
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: Read Text From Windows Confirmation Dialog?

03 Mar 2020, 16:49

What is the class name of the text control? TLabel?
ControlGetText, Label, TLabel1, ahk_id %lParam%

Code: Select all

Global Criteria := "Confirmation ahk_class TMessageForm ahk_exe Product.exe"
Global PopupMsg := "Do you want to update the promo at all locations?"

Gui +LastFound
DllCall("RegisterShellHookWindow", "Ptr", WinExist())
OnMessage(DllCall("RegisterWindowMessage", "Str", "SHELLHOOK"), "OnShellMessage")
 
OnShellMessage(wParam, lParam) {
    If (wParam == 1) { ; HSHELL_WINDOWCREATED
        If (WinExist(Criteria . " ahk_id" . lParam)) {
            ControlGetText, Label, TLabel1, ahk_id %lParam%
            If (Label == PopupMsg) {
                ControlClick, &No, ahk_id %lParam%                
            }
        }
    }
}
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Read Text From Windows Confirmation Dialog?

03 Mar 2020, 17:03

Using ImageSearch with a screen grab of the text in the dialog box as reference would be faster and more reliable than OCR.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 351 guests