supraspecies

Detect an MsgBox

8 posts in this topic

#1 ·  Posted

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



#2 ·  Posted

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

#4 ·  Posted (edited)

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

#6 ·  Posted

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted

Thank you for your help, I got it working.

Share this post


Link to post
Share on other sites

#8 ·  Posted

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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