hiimjoey11 Posted February 4, 2015 Posted February 4, 2015 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?
Moderators SmOke_N Posted February 4, 2015 Moderators Posted February 4, 2015 (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 February 4, 2015 by SmOke_N 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.
water Posted February 4, 2015 Posted February 4, 2015 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
hiimjoey11 Posted February 4, 2015 Author Posted February 4, 2015 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?
hiimjoey11 Posted February 4, 2015 Author Posted February 4, 2015 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 :/
hiimjoey11 Posted February 4, 2015 Author Posted February 4, 2015 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?
hiimjoey11 Posted February 4, 2015 Author Posted February 4, 2015 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!
Moderators SmOke_N Posted February 4, 2015 Moderators Posted February 4, 2015 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? 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.
hiimjoey11 Posted February 4, 2015 Author Posted February 4, 2015 (edited) I guess you're not using a current version of AutoIt? v3.3.8.1 EDIT: Updated and yours worked like a charm Thank you EDIT2: Only worked if i run it, not if a build it... hmm Edited February 4, 2015 by hiimjoey11
Moderators SmOke_N Posted February 4, 2015 Moderators Posted February 4, 2015 I'll be damned... It appears the msgbox isn't even running at all compiled. 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.
hiimjoey11 Posted February 4, 2015 Author Posted February 4, 2015 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
Moderators SmOke_N Posted February 4, 2015 Moderators Posted February 4, 2015 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. 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.
Solution hiimjoey11 Posted February 4, 2015 Author Solution Posted February 4, 2015 (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 February 4, 2015 by hiimjoey11
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now