Jump to content
supraspecies

Detect an MsgBox

Recommended Posts

supraspecies

I tied an MsgBox to ESC key. And I want to have only one instance of MsgBox regardless of how many times ESC key is pressed. Here's my code:

Func _exit()
   If WinExists($title, "Do you want to quit the setup?") Then
      WinActivate($title, "Do you want to quit the setup?")
   Else
      $msg = MsgBox(262180, $title, "Do you want to quit the setup?")
         If $msg = 6 Then
            ProcessClose($pid)
            Exit 
         EndIf
    EndIf
EndFunc

The script is supposed to focus on the MsgBox if it already exists. But it doesn't. Instead, it creates a new MsgBox every time ESC is pressed.  It seems that it doesn't detect MsgBox as a window. How do I get around that?

Share this post


Link to post
Share on other sites
water

Best way to get help on the forum is to post a working reproducer script! So everyone can test without having to write a lot of code just to get it running.
How do you call function _Exit?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
supraspecies

Well, there isn't much more to the script than I already posted. I call the function with ESC key like this:

HotKeySet("{Esc}", "_Exit")

And it does work. It creates an MsgBox. Some fault is in the function itself.

Share this post


Link to post
Share on other sites
water

There must be more, because just by having the HotKeySet and the function your script would end in a split second ... ;)

BTW: Variables $title and $pid are undefined as well!

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
supraspecies

Sorry, I didn't think it was necessary because my script is very simple. Here is the whole script:

_singleton("Setup Launcher", 0)
$title = "Setup"
$pid = Run(@ScriptDir & "\setup.exe")
ProcessWait($pid)
While ProcessExists($pid)
    If WinActive("[REGEXPTITLE:Installation;CLASS:#32770]") Then
        HotKeySet("{Esc}", "_Exit")
    Else
        HotKeySet("{Esc}")
    EndIf
WEnd

Func _exit()
   If WinExists($title, "Do you want to quit the setup?") Then
      WinActivate($title, "Do you want to quit the setup?")
   Else
      $msg = MsgBox(262180, $title, "Do you want to quit the setup?")
         If $msg = 6 Then
            ProcessClose($pid)
            Exit 
         EndIf
   EndIf
EndFunc

 

Edited by supraspecies

Share this post


Link to post
Share on other sites
water

Something like this:

#include <Misc.au3>
#include <MsgBoxConstants.au3>

_Singleton("Setup Launcher", 0)
Global $fMsgBox = False
Global $sTitle = "Setup"
Global $iPID = Run(@ScriptDir & "\setup.exe")
; ProcessWait($iPID) ; <== Not needed. You only get the PID when the process exists
While ProcessExists($iPID)
    If WinActive("[REGEXPTITLE:Setup;CLASS:#32770]") Then
        HotKeySet("{Esc}", "_Exit")
    Else
        HotKeySet("{Esc}")
    EndIf
    Sleep(100) ; <== So your script does not eat up all the CPU power
WEnd

Func _Exit()
    ;   If WinExists($sTitle, "Do you want to quit the setup?") Then ; <== Not needed as the MsgBox always stays on top/active
    ;       WinActivate($sTitle, "Do you want to quit the setup?")
    ;   Else
    If $fMsgBox = True Then Return
    $fMsgBox = True
    $iMsg = MsgBox(BitOR($MB_YESNO, $MB_ICONQUESTION, $MB_TASKMODAL), $sTitle, "Do you want to quit the setup?")
    If $iMsg = 6 Then
        ProcessClose($iPID)
        Exit
    EndIf
    $fMsgBox = False
    ;   EndIf
EndFunc   ;==>_Exit

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
supraspecies

Thank you for your help, I got it working.

Share this post


Link to post
Share on other sites
water

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×