Page 1 of 1

Read Text From Windows Confirmation Dialog?

Posted: 03 Mar 2020, 11:53
by MaxAstro
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 935 times
Here is what WindowSpy says about the prompt:
Wspy.png
Wspy.png (24.49 KiB) Viewed 935 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?

Re: Read Text From Windows Confirmation Dialog?

Posted: 03 Mar 2020, 12:26
by Rohwedder
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

Re: Read Text From Windows Confirmation Dialog?

Posted: 03 Mar 2020, 12:36
by MaxAstro
Unfortunately there are other confirmation dialogs generated by the same program that I need to avoid clicking on.

Re: Read Text From Windows Confirmation Dialog?

Posted: 03 Mar 2020, 12:47
by Alguimist
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?

Re: Read Text From Windows Confirmation Dialog?

Posted: 03 Mar 2020, 16:10
by wineguy
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

Re: Read Text From Windows Confirmation Dialog?

Posted: 03 Mar 2020, 16:33
by MaxAstro
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...

Re: Read Text From Windows Confirmation Dialog?

Posted: 03 Mar 2020, 16:49
by Alguimist
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%                
            }
        }
    }
}

Re: Read Text From Windows Confirmation Dialog?

Posted: 03 Mar 2020, 17:03
by boiler
Using ImageSearch with a screen grab of the text in the dialog box as reference would be faster and more reliable than OCR.