hiimjoey11

Return value from MsgBox

14 posts in this topic

I am trying to use MrCreatoR's _MoveMsgBox from the bottom of this topic: '?do=embed' frameborder='0' data-embedContent>>

But I also need it to return the value of that MsgBox.  Is this possible?

So instead of his original:

Func _MoveMsgBox($Flag, $Title, $Text, $Time=0)
    Run(@AutoItExe & ' /AutoIt3ExecuteLine  "MsgBox(' & $Flag & ', ''' & $Title & ''', ''' & $Text & ''',' & $Time & ')"')
EndFunc

I would need something like this (which doesnt work):

Func _MoveMsgBox($Flag, $Title, $Text, $Time=0)
    Return Run(@AutoItExe & ' /AutoIt3ExecuteLine  "MsgBox(' & $Flag & ', ''' & $Title & ''', ''' & $Text & ''',' & $Time & ')"')
EndFunc

Any suggestions?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Could probably manipulate using the exit code:

#include <ProcessConstants.au3>
#include <WinAPIProc.au3>
#include <WinAPISys.au3>
ConsoleWrite("MsgBox Return Value: " & _MoveMsgBox(64, "Test", "Some Text") & @CRLF)

Func _MoveMsgBox($Flag, $Title, $Text, $Time=0, $bReturnVal = True)
    Local $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine  "Exit MsgBox(' & $Flag & ', ''' & $Title & ''', ''' & $Text & ''',' & $Time & ')"')
    If Not $bReturnVal Then Return $iPID

    Local $iAccess = ((_WinAPI_GetVersion() >= 6.0) ? _
        $PROCESS_QUERY_LIMITED_INFORMATION : $PROCESS_QUERY_INFORMATION)
    Local $hProcess = _WinAPI_OpenProcess($PROCESS_QUERY_LIMITED_INFORMATION, 0, $iPID)
    If @error Or Not $hProcess Then Return $iPID

    While ProcessExists($iPID)
        Sleep(10)
    WEnd
    Local $iRet = Int(_WinAPI_GetExitCodeProcess($hProcess))
    _WinAPI_CloseHandle($hProcess)
    Return $iRet
EndFunc

I thought I wrote a pretty simple msgbox move/etc options years ago, I might have to dig for it.

Hmm, don't know if it's simple for a novice but you've been around for a bit... here: 

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Another solution:

Share this post


Link to post
Share on other sites

Run only returns the ID of the started process. Maybe RunWait gives you the return value of MsgBox?

Need to check.


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

Could probably manipulate using the exit code:

#include <ProcessConstants.au3>
#include <WinAPIProc.au3>
#include <WinAPISys.au3>
ConsoleWrite("MsgBox Return Value: " & _MoveMsgBox(64, "Test", "Some Text") & @CRLF)

Func _MoveMsgBox($Flag, $Title, $Text, $Time=0, $bReturnVal = True)
    Local $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine  "Exit MsgBox(' & $Flag & ', ''' & $Title & ''', ''' & $Text & ''',' & $Time & ')"')
    If Not $bReturnVal Then Return $iPID

    Local $iAccess = ((_WinAPI_GetVersion() >= 6.0) ? _
        $PROCESS_QUERY_LIMITED_INFORMATION : $PROCESS_QUERY_INFORMATION)
    Local $hProcess = _WinAPI_OpenProcess($PROCESS_QUERY_LIMITED_INFORMATION, 0, $iPID)
    If @error Or Not $hProcess Then Return $iPID

    While ProcessExists($iPID)
        Sleep(10)
    WEnd
    Local $iRet = Int(_WinAPI_GetExitCodeProcess($hProcess))
    _WinAPI_CloseHandle($hProcess)
    Return $iRet
EndFunc

 

Thanks for this! But it doesn't work.. "Error: can't open include file <WinAPIPRoc.au3> and same with <WinAPISys.au3>.  Is that part needed? What exactly does this do?

Share this post


Link to post
Share on other sites

Run only returns the ID of the started process. Maybe RunWait gives you the return value of MsgBox?

Need to check.

Func _MoveMsgBox($Flag, $Title, $Text, $Time=0)
    $value =  RunWait(@AutoItExe & ' /AutoIt3ExecuteLine  "MsgBox(' & $Flag & ', ''' & $Title & ''', ''' & $Text & ''',' & $Time & ')"')
    MsgBox(0, "", $value)
    Return $value
EndFunc

This returns 0 for them all :/

Share this post


Link to post
Share on other sites
 

 

You can't get the return value from AutoIt3ExecuteLine. Next time write ALL THE INFORMATION or in this forum every single user criticize you for the behavior, remember it  ;)

This is a simple example of inter-communication between script, autoit is single threaded so we don't have many choice. In alternative to the second file creation ( the text file ) you can use the clipboard. An advanced example can use instead >WM_COPYDATA

; Johnmcloud - 2014

Local $sReturn = _MsgBox_SERVICE_NOTIFICATION_TIMEOUT("Hello World!", "Johnmcloud!", 5000)
Switch $sReturn
    Case 1
        MsgBox(64, "Result", "You have pressed OK")
    Case 2
        MsgBox(64, "Result", "You have pressed Cancel or X")
    Case -1
        MsgBox(64, "Result", "Timeout")
    Case Else
        MsgBox(32, "Error", "Value not expected")
EndSwitch

Func _MsgBox_SERVICE_NOTIFICATION_TIMEOUT($sTitle, $sText, $iTimeout)
    Local $iBegin, $iFinish, $iPID, $sReturn
    Local $sTMP_Au3 = @TempDir & "~TEMP.au3", $sTMP_Txt = @TempDir & "~TEMP.txt"

    ; create temporany au3 file - 2097152 + 1 = $MB_SERVICE_NOTIFICATION + OK
    Local $hFile = FileOpen($sTMP_Au3, 2)
    FileWrite($hFile, '#NoTrayIcon' & @CRLF)
    FileWrite($hFile, 'Local $hFile = FileOpen("' & $sTMP_Txt & '", 2)' & @CRLF)
    FileWrite($hFile, 'Local $sReturn = MsgBox(2097152 + 1, "' & $sTitle & '", "' & $sText & '")' & @CRLF)
    FileWrite($hFile, 'If $sReturn = 1 Then FileWrite($hFile, "1")' & @CRLF)
    FileWrite($hFile, 'If $sReturn = 2 Then FileWrite($hFile, "2")' & @CRLF)
    FileWrite($hFile, 'FileClose($hFile)')
    FileClose($hFile)
    ; end

    $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sTMP_Au3 & '"')
    $iBegin = TimerInit()
    Do
        Sleep(100)
        $iFinish = TimerDiff($iBegin)
    Until Not ProcessExists($iPID) Or $iFinish >= $iTimeout

    If $iFinish >= $iTimeout Then ; timed out so close the MsgBox
        WinClose($sTitle, $sText) ; close the MsgBox
        $sReturn = -1 ; TIMEOUT
    Else
        $hFile = FileOpen($sTMP_Txt, 0)
        If FileReadLine($hFile, 1) = "1" Then $sReturn = 1 ; OK = 1
        If FileReadLine($hFile, 1) = "2" Then $sReturn = 2 ; CANCEL = 2
        FileClose($hFile)
    EndIf
    FileDelete($sTMP_Au3)
    FileDelete($sTMP_Txt)
    Return $sReturn
EndFunc ;==>_MsgBox_SERVICE_NOTIFICATION_TIMEOUT


 

 

Johnmcloud, anyway to do this without writing to files?

Share this post


Link to post
Share on other sites

Could probably manipulate using the exit code:

I thought I wrote a pretty simple msgbox move/etc options years ago, I might have to dig for it.

Hmm, don't know if it's simple for a novice but you've been around for a bit... here: 

 

I'll have to try it if there isn't a simpler solution, thank you!  :sorcerer:

Share this post


Link to post
Share on other sites

Thanks for this! But it doesn't work.. "Error: can't open include file <WinAPIPRoc.au3> and same with <WinAPISys.au3>.  Is that part needed? What exactly does this do?

I guess you're not using a current version of AutoIt?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I guess you're not using a current version of AutoIt?

v3.3.8.1

EDIT: Updated and yours worked like a charm  :thumbsup:   Thank you

EDIT2: Only worked if i run it, not if a build it... hmm

Edited by hiimjoey11

Share this post


Link to post
Share on other sites

I'll be damned... It appears the msgbox isn't even running at all compiled.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I'll be damned... It appears the msgbox isn't even running at all compiled.

haha but it works perfectly if you just run it ;)

Share this post


Link to post
Share on other sites

Well, this definitely seems like an issue to me.  I can't get AutoIt3ExecuteLine to run without using the AutoIt.exe stub.  It will not run for me on any au3.exe.  Unfortunately, I've run out of time to mess around with it.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Well, this definitely seems like an issue to me.  I can't get AutoIt3ExecuteLine to run without using the AutoIt.exe stub.  It will not run for me on any au3.exe.  Unfortunately, I've run out of time to mess around with it.

No problem! Thanks for trying.. If you get bored in the next few days and decide to look at it let me know :) Ill keep an eye on this forum for a few days.

EDIT: I got it! I finally read the help file for command line, and to get your line of code to work with compiled scripts you need to include this line! Thanks for pointing me in the right direction!  Works flawless now.

#pragma compile(AutoItExecuteAllowed, True)

_MoveMsgBox(0, "Test", "testing")

Func _MoveMsgBox($Flag, $Title, $Text, $Time=0, $bReturnVal = True)
    Local $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine  "Exit MsgBox(' & $Flag & ', ''' & $Title & ''', ''' & $Text & ''',' & $Time & ')"')
    If Not $bReturnVal Then Return $iPID

    Local $iAccess = ((_WinAPI_GetVersion() >= 6.0) ? _
        $PROCESS_QUERY_LIMITED_INFORMATION : $PROCESS_QUERY_INFORMATION)
    Local $hProcess = _WinAPI_OpenProcess($PROCESS_QUERY_LIMITED_INFORMATION, 0, $iPID)
    If @error Or Not $hProcess Then Return $iPID

    While ProcessExists($iPID)
        Sleep(10)
    WEnd
    Local $iRet = Int(_WinAPI_GetExitCodeProcess($hProcess))
    _WinAPI_CloseHandle($hProcess)
    Return $iRet
EndFunc
Edited by hiimjoey11

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