Jump to content

Move MsgBox (/AutoIt3ExecuteScript)


 Share

Recommended Posts

Requires the beta version of AutoIt.

A standard MsgBox is centered on the screen.

If you want the MsgBox to be display elsewhere, consider making a GUI.

For those not ready to make a GUI version of the standard MsgBox, see each User Defined Function (UDF) below. They use the @AutoItExe & /AutoIt3ExecuteScript features to launch another script to move the standard MsgBox.

A standard MsgBox has a flag, a title and some text.

MsgBox(0, "testTitle", "testText")

To use the Move Message Box UDF below, copy the code from the first code box and place it near the bottom of your own script.

Then cut out this line:

_MoveMsgBox(0, "testTitle", "testText", 0, 10)

and paste into the main part of your script.

Replace "testTitle" & "testText" with your info.

Then replace the "0, 10" part with the x and y coordinates you want...

; Move Message Box
; Author - herewasplato

_MoveMsgBox(0, "testTitle", "testText", 0, 10)

Func _MoveMsgBox($MBFlag, $MBTitle, $MBText, $x, $y)
    Local $file = FileOpen(EnvGet("temp") & "\MoveMB.au3", 2)
    If $file = -1 Then Return;if error, give up on the move
    
    Local $line1 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
    Local $line2 = 'WinWait("' & $MBTitle & '", "' & $MBText & '")'
    Local $line3 = 'WinMove("' & $MBTitle & '", "' & $MBText & '"' & ', ' & $x & ', ' & $y & ')'
    FileWrite($file, $line1 & @CRLF & $line2 & @CRLF & $line3)
    FileClose($file)
    
    Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\MoveMB.au3")
    
    MsgBox($MBFlag, $MBTitle, $MBText)
    
    While Not FileDelete(EnvGet("temp") & "\MoveMB.au3")
        Sleep(10)
    WEnd
EndFunc;==>_MoveMsgBox

If you want the MsgBox to move around a few times before stopping, consider using the UDF below.

Follow the instructions mentioned for the UDF above but after replacing the x and y coordinates,

replace 22 with the number of times that you want the

MsgBox to move around on the screen before stopping

Then replace 333 with a lower number to make each move go faster.

; Random Move Message Box
; Author - herewasplato

_RandomMoveMsgBox(0, "testTitle", "testText", 0, 10, 22, 333)

Func _RandomMoveMsgBox($MBFlag, $MBTitle, $MBText, $x, $y, $moves, $speed)
    Local $file = FileOpen(EnvGet("temp") & "\RandomMoveMB.au3", 2)
    If $file = -1 Then Return;if error, give up on the move
    
    Local $line1 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
    Local $line2 = 'WinWait("' & $MBTitle & '", "' & $MBText & '")'
    Local $line3 = 'For $m = 1 to ' & $moves
    Local $line4 = '    WinMove("' & $MBTitle & '", "' & $MBText & '"' & ', Random(0, @DesktopWidth - 150, 1), Random(0, @DesktopHeight - 150, 1))'
    Local $line5 = '    Sleep(' & $speed & ')'
    Local $line6 = 'Next'
    FileWrite($file, $line1 & @CRLF & $line2 & @CRLF & $line3 & @CRLF)
    FileWrite($file, $line4 & @CRLF & $line5 & @CRLF & $line6)
    FileClose($file)
    
    Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\RandomMoveMB.au3")
    
    MsgBox($MBFlag, $MBTitle, $MBText)
    
    While Not FileDelete(EnvGet("temp") & "\RandomMoveMB.au3")
        Sleep(10)
    WEnd
EndFunc;==>_RandomMoveMsgBox
Of course, the combination of the @AutoItExe & /AutoIt3ExecuteScript features can do much more than move a MsgBox around.

Edit: Anyone want to make one spiral from the outer edge of the screen to the center - or vice versa...

You can use FileWriteLn and an array for the temp code.

Edit2: There was a reason for the "random code":

http://www.autoitscript.com/forum/index.php?showtopic=22520

Edit3: Updated the file delete since the file did not delete on some systems. In rare cases this loop might go on forever.

Edit4: Thanks go out to the entire AutoIt team and especially jpm, Valik and SlimShady:

http://www.autoitscript.com/forum/index.ph...ndpost&p=156446

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Variations on a theme:

; Move Message Box - with timeout
; Author - herewasplato

_MoveMsgBox(0, "testTitle", "testText", 3, 0, 10)

Func _MoveMsgBox($MBFlag, $MBTitle, $MBText, $timeout, $x, $y)
    Local $file = FileOpen(EnvGet("temp") & "\MoveMB.au3", 2)
    If $file = -1 Then Return;if error, give up on the move
    
    Local $line1 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
    Local $line2 = 'WinWait("' & $MBTitle & '", "' & $MBText & '")'
    Local $line3 = 'WinMove("' & $MBTitle & '", "' & $MBText & '"' & ', ' & $x & ', ' & $y & ')'
    FileWrite($file, $line1 & @CRLF & $line2 & @CRLF & $line3)
    FileClose($file)
    
    Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\MoveMB.au3")
    
    MsgBox($MBFlag, $MBTitle, $MBText, $timeout)
    
    While Not FileDelete(EnvGet("temp") & "\MoveMB.au3")
        Sleep(10)
    WEnd
EndFunc  ;==>_MoveMsgBox
; Random Move Message Box - with timeout
; Author - herewasplato

_RandomMoveMsgBox(0, "testTitle", "testText", 3, 0, 10, 22, 333)

Func _RandomMoveMsgBox($MBFlag, $MBTitle, $MBText, $timeout, $x, $y, $moves, $speed)
    Local $file = FileOpen(EnvGet("temp") & "\RandomMoveMB.au3", 2)
    If $file = -1 Then Return;if error, give up on the move
    
    Local $line1 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
    Local $line2 = 'WinWait("' & $MBTitle & '", "' & $MBText & '")'
    Local $line3 = 'For $m = 1 to ' & $moves
    Local $line4 = '    WinMove("' & $MBTitle & '", "' & $MBText & '"' & ', Random(0, @DesktopWidth - 150, 1), Random(0, @DesktopHeight - 150, 1))'
    Local $line5 = '    Sleep(' & $speed & ')'
    Local $line6 = 'Next'
    FileWrite($file, $line1 & @CRLF & $line2 & @CRLF & $line3 & @CRLF)
    FileWrite($file, $line4 & @CRLF & $line5 & @CRLF & $line6)
    FileClose($file)
    
    Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\RandomMoveMB.au3")
    
    MsgBox($MBFlag, $MBTitle, $MBText, $timeout)
    
    While Not FileDelete(EnvGet("temp") & "\RandomMoveMB.au3")
        Sleep(10)
    WEnd
EndFunc  ;==>_RandomMoveMsgBox
Might want to set the timeout long enough for the moves to complete.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

This is a MsgBox using /AutoIt3ExecuteLine that is good for someone who has troubles hitting the OK button with the mouse.

_MsgBox('My MsgBox', 'Press OK to proceed')

Func _MsgBox($title, $text)
    Local $pid, $pos
    MouseMove(@DesktopWidth / 2, @DesktopHeight / 2 + 60, 1)
    $pid = Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & _
            '"MsgBox(0x0,''' & $title & ''',''' & $text & ''')"')
    WinWait($title, $text) 
    While WinExists($title, $text)
        $pos = MouseGetPos()
        If Not @error Then
            WinMove($title, $text, $pos[0] - 60, $pos[1] - 80)
        EndIf
        Sleep(10)
    WEnd
    ProcessWaitClose($pid)
EndFunc
Edited by MHz
Link to comment
Share on other sites

Well this is interesting... turns out somehow you can delete the file while it's still running. The move script runs until the for loop is finished, regardless of whether the message box is there or not.

Yep - once the code is in ram, you can delete or write over the temp au3 - thus getting it ready for the next time the main script calls it. The same au3 can be used for as many things and as many times as you wish... if used carefully. Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Yep - once the code is in ram, you can delete or write over the temp au3 - thus getting it ready for the time the main script calls it. The same au3 can be used for as many things and as many times as you wish... if used carefully.

Well that's cool. I guess I was under the impression it acted like an exe, where it's constantly being used as it is run. But I guess if it's being fully read into ram, this makes more sense.

Link to comment
Share on other sites

  • Moderators

Anyone know why the Line Feed doesn't work on this (@CRLF / @LF) No big deal, @CR does... just curious.

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.

Link to comment
Share on other sites

  • 1 month later...

From this request: http://www.autoitscript.com/forum/index.php?showtopic=24730

; Message Box with Sound
; Author - herewasplato

_MsgBoxSound(0, "Done", "Thank You! Come Again!", "C:\WINDOWS\Media\tada.wav", 10)

Func _MsgBoxSound($MBFlag, $MBTitle, $MBText, $MBSound, $timeout)
    Local $file = FileOpen(EnvGet("temp") & "\MBSound.au3", 2)
    If $file = -1 Then MsgBox(0, "", "Error opening file.")
    
    Local $line1 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
    Local $line2 = 'WinWait("' & $MBTitle & '", "' & $MBText & '")'
    Local $line3 = 'SoundPlay("' & $MBSound & '", 1)'
    
    FileWrite($file, $line1 & @CRLF & $line2 & @CRLF & $line3)
    FileClose($file)
    
    Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\MBSound.au3")
    
    MsgBox($MBFlag, $MBTitle, $MBText, $timeout)
    
    While Not FileDelete(EnvGet("temp") & "\MBSound.au3")
        Sleep(10)
    WEnd
EndFunc  ;==>_MsgBoxSound

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • 1 month later...
  • Moderators

I started playing with this tonight, and couldn't stop... I had an issue before with @CRLF / @LF / @CR when trying to do multiple lines, I also liked what MHz showed, and someone had something about making it return a value, so I finally played with STDOutRead()...

Anyway, it now supports multiple lines / a virtual multithreaded MsgBox() (don't know what else to call it :))/ and Return Value from it... Have fun (Oh and if you see something to make it easier/better feel free :(

$xpos = 50
$ypos = 30
$TestValue = _MoveMsgBox(68, "Testing Move MsgBox", "This is line one" & @LF & _
        "This is line two" & @LF & _
        "This is line three" & @LF & _
        'Would you like to continue?', 0, $xpos, $ypos, 1)

If $TestValue = 6 Then
    MsgBox(64, 'Info:', 'You Chose Yes')
ElseIf $TestValue = 7 Then
    MsgBox(64, 'Info:', 'You Chose No')
Else
    MsgBox(48, 'Error:', 'Something is wrong with the return values')
EndIf

Func _MoveMsgBox($MBFlag, $MBTitle, $MBText, $MBTimeOut, $MBxPos, $MByPos, $MBContinue = 0)
    Local $MBFile = FileOpen(EnvGet("temp") & "\MiscMMB.xxx", 2)
    Local $MBFile2 = FileOpen(EnvGet("temp") & "\MiscMMB2.xxx", 2)
    If $MBFile = -1 Or $MBFile2 = -1 Then Return
    
    Local $LineDelimter = '', $MBPID1 = '', $MBPID2 = ''
    
    If UBound(StringSplit($MBText, @CRLF, 1)) - 2 > 0 Then
        $LineDelimter = @CRLF
    ElseIf UBound(StringSplit($MBText, @CR, 1)) - 2 > 0 Then
        $LineDelimter = @CR
    ElseIf UBound(StringSplit($MBText, @LF, 1)) - 2 > 0 Then
        $LineDelimter = @LF
    EndIf
    
    Local $SSpMB = StringSplit($MBText, $LineDelimter, 1)
    If UBound($SSpMB) - 2 > 0  And $LineDelimter <> '' Then
        Local $MBLine1 = '#NoTrayIcon'
        Local $MBLine2 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
        FileWriteLine($MBFile, $MBLine1 & @CRLF & $MBLine2)
        
        $MsgBoxLine1 = '#NoTrayIcon'
        FileWriteLine($MBFile2, $MsgBoxLine1)
        
        Local $MsgBoxLine[UBound($SSpMB)]
        Local $LinesToShow = ''
        For $iCount = 1 To UBound($SSpMB) - 1
            FileWriteLine($MBFile, '$MsgBoxLine' & $iCount & ' = "' & $SSpMB[$iCount] & '"')
            FileWriteLine($MBFile2, '$MsgBoxLine' & $iCount & ' = "' & $SSpMB[$iCount] & '"')
            If $iCount < UBound($SSpMB) - 1 Then
                $LinesToShow &= '$MsgBoxLine' & $iCount & ' & @CRLF & '
            Else
                $LinesToShow &= '$MsgBoxLine' & $iCount
            EndIf
        Next
        
        Local $MBLine3 = 'WinWait("' & $MBTitle & '", ' & '$LinesToShow' & ')'
        Local $MBLine4 = 'WinMove("' & $MBTitle & '", ' & '$LinesToShow' & ', ' & $MBxPos & ', ' & $MByPos & ')'
        FileWriteLine($MBFile, '$LinesToShow = ' & $LinesToShow & @CRLF & $MBLine3 & @CRLF & $MBLine4)
        FileWriteLine($MBFile2, '$LinesToShow = ' & $LinesToShow)
        
        Local $MsgBoxLine2 = '$MsgBoxValue = MsgBox(' & $MBFlag & ', ''' & $MBTitle & ''', ' & '$LinesToShow' & ', ''' & $MBTimeOut & ''')'
        Local $MsgBoxLine3 = 'ConsoleWrite(' & "'MsgBoxSays'" & ' & $MsgBoxValue & ' & "'Return'" & ')'
        FileWriteLine($MBFile2, $MsgBoxLine2 & @CRLF & $MsgBoxLine3)
        FileClose($MBFile)
        FileClose($MBFile2)
    Else
        Local $MBLine1 = '#NoTrayIcon'
        Local $MBLine2 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
        Local $MBLine3 = 'WinWait("' & $MBTitle & '", "' & $MBText & '")'
        Local $MBLine4 = 'WinMove("' & $MBTitle & '", "' & $MBText & '"' & ', ' & $MBxPos & ', ' & $MByPos & ')'
        FileWrite($MBFile, $MBLine1 & @CRLF & $MBLine2 & @CRLF & $MBLine3 & @CRLF & $MBLine4)
        FileClose($MBFile)
        
        Local $MsgBoxLine1 = '#NoTrayIcon'
        Local $MsgBoxLine2 = '$MsgBoxValue = MsgBox(' & $MBFlag & ', ''' & $MBTitle & ''', ''' & $MBText & ''', ''' & $MBTimeOut & ''')'
        Local $MsgBoxLine3 = 'ConsoleWrite(' & "'MsgBoxSays'" & ' & $MsgBoxValue & ' & "'Return'" & ')'
        FileWrite($MBFile2, $MsgBoxLine1 & @CRLF & $MsgBoxLine2 & @CRLF & $MsgBoxLine3)
        FileClose($MBFile2)
    EndIf
    
    $MBPID1 = Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\MiscMMB.xxx")
    $MBPID2 = Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & EnvGet("temp") & "\MiscMMB2.xxx", @WorkingDir, 0, 6)
    
    WinWait($MBTitle, $MBText, 2)
    While (Not FileDelete(EnvGet("temp") & "\MiscMMB.xxx") Or Not FileDelete(EnvGet("temp") & "\MiscMMB2.xxx"))
        Sleep(10)
    WEnd
    
    If $MBContinue Then
        While 1
            $StdOutReadValue = StdoutRead($MBPID2)
            If StringInStr($StdOutReadValue, 'MsgBoxSays') Then
                $a_Array = StringRegExp($StdOutReadValue, '(?:MsgBoxSays)(.*?)(?:Return)', 3)
                If Not @error Then Return $a_Array[0]
                Return 0
            EndIf
            Sleep(10)
        WEnd
    EndIf
    Return 0
EndFunc;==>_MoveMsgBox

Edit:

Pretty bulky huh :D

Edited 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.

Link to comment
Share on other sites

...and Return Value from it...

I could not get yours to work.

It could not find either MiscMMB.xxx or MiscMMB2.xxx

Then I ran one of my first versions and the msgbox stayed put way too long before the move. The only major change to the system running the code was a new version of antivirus software. I changed a setting within that software from "Disable file cache" to "Use default file cache size" and all was as before... and your code ran as expected.

So, I say all of that to say this; you might want to change WinWait($MBTitle, $MBText, 2) to handle really slow systems.

I added the return value - I might not have done it the right way:

; Move Message Box - with timeout - with return
; Author - herewasplato

$ans = _MoveMsgBox(4, "testTitle", "testText", 15, 0, 10)
MsgBox(0, "Returned", $ans)

Func _MoveMsgBox($MBFlag, $MBTitle, $MBText, $timeout, $x, $y)
    Local $file = FileOpen(EnvGet("temp") & "\MoveMB.au3", 2)
    If $file = -1 Then Return;if error, give up on the move
    
    Local $line1 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
    Local $line2 = 'WinWait("' & $MBTitle & '", "' & $MBText & '")'
    Local $line3 = 'WinMove("' & $MBTitle & '", "' & $MBText & '"' & ', ' & $x & ', ' & $y & ')'
    FileWrite($file, $line1 & @CRLF & $line2 & @CRLF & $line3)
    FileClose($file)
    
    Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\MoveMB.au3")
    
    Sleep(1000)
    
    Local $ans = MsgBox($MBFlag, $MBTitle, $MBText, $timeout)
    
    While Not FileDelete(EnvGet("temp") & "\MoveMB.au3")
        Sleep(10)
    WEnd
    
    Return ($ans)
EndFunc ;==>_MoveMsgBox
This version does not support multi-line text.

Try it without the Sleep(1000) line :-)

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • Moderators

I could not get yours to work.

It could not find either MiscMMB.xxx or MiscMMB2.xxx

Then I ran one of my first versions and the msgbox stayed put way too long before the move. The only major change to the system running the code was a new version of antivirus software. I changed a setting within that software from "Disable file cache" to "Use default file cache size" and all was as before... and your code ran as expected.

So, I say all of that to say this; you might want to change WinWait($MBTitle, $MBText, 2) to handle really slow systems.

I added the return value - I might not have done it the right way:

CODE
; Move Message Box - with timeout - with return

; Author - herewasplato

$ans = _MoveMsgBox(4, "testTitle", "testText", 15, 0, 10)

MsgBox(0, "Returned", $ans)

Func _MoveMsgBox($MBFlag, $MBTitle, $MBText, $timeout, $x, $y)

Local $file = FileOpen(EnvGet("temp") & "\MoveMB.au3", 2)

If $file = -1 Then Return;if error, give up on the move

Local $line1 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'

Local $line2 = 'WinWait("' & $MBTitle & '", "' & $MBText & '")'

Local $line3 = 'WinMove("' & $MBTitle & '", "' & $MBText & '"' & ', ' & $x & ', ' & $y & ')'

FileWrite($file, $line1 & @CRLF & $line2 & @CRLF & $line3)

FileClose($file)

Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\MoveMB.au3")

Sleep(1000)

Local $ans = MsgBox($MBFlag, $MBTitle, $MBText, $timeout)

While Not FileDelete(EnvGet("temp") & "\MoveMB.au3")

Sleep(10)

WEnd

Return ($ans)

EndFunc ;==>_MoveMsgBox

This version does not support multi-line text.

Try it without the Sleep(1000) line :-)

The .xxx was something I was testing, I meant to change that back to .txt. Sorry.

The return values were wrong in the one I sent you, because the Flag was set incorrectly, I was testing something and forgot to set it back to 68. If you ran the one in the post above it would have given the correct return values.

As per the PM earlier, I am not using WinWait() in mine but WinExists() in a While/WEnd loop which if WinWait() is causing issues on a slower computer, WinExists() may be a bigger issue. But again that could be easily solved with another loop making sure that the position is true.

Here's an example, this should fix any issue you are having with a slow computer:

$xpos = 50
$ypos = 30
$TestValue = _MoveMsgBox(68, "Testing Move MsgBox", 'Would you like to continue?', 0, $xpos, $ypos, 1)

If $TestValue = 6 Then
    MsgBox(64, 'Info:', 'You Chose Yes')
ElseIf $TestValue = 7 Then
    MsgBox(64, 'Info:', 'You Chose No')
Else
    MsgBox(48, 'Error:', 'Something is wrong with the return values')
EndIf

Func _MoveMsgBox($MBFlag, $MBTitle, $MBText, $MBTimeOut, $MBxPos, $MByPos, $MBContinue = 0)
    Local $MBFile = FileOpen(EnvGet("temp") & "\MiscMMB.txt", 2)
    Local $MBFile2 = FileOpen(EnvGet("temp") & "\MiscMMB2.txt", 2)
    If $MBFile = -1 Or $MBFile2 = -1 Then Return 0
    
    Local $LineDelimter = '', $MBPID1 = '', $MBPID2 = ''
    
    If UBound(StringSplit($MBText, @CRLF, 1)) - 2 > 0 Then
        $LineDelimter = @CRLF
    ElseIf UBound(StringSplit($MBText, @CR, 1)) - 2 > 0 Then
        $LineDelimter = @CR
    ElseIf UBound(StringSplit($MBText, @LF, 1)) - 2 > 0 Then
        $LineDelimter = @LF
    EndIf
    
    Local $SSpMB = StringSplit($MBText, $LineDelimter, 1)
    If UBound($SSpMB) - 2 > 0 And $LineDelimter <> '' Then
        Local $MBLine1 = '#NoTrayIcon'
        Local $MBLine2 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
        FileWriteLine($MBFile, $MBLine1 & @CRLF & $MBLine2)
        
        $MsgBoxLine1 = '#NoTrayIcon'
        FileWriteLine($MBFile2, $MsgBoxLine1)
        
        Local $MsgBoxLine[UBound($SSpMB)]
        Local $LinesToShow = ''
        For $iCount = 1 To UBound($SSpMB) - 1
            FileWriteLine($MBFile, '$MsgBoxLine' & $iCount & ' = "' & $SSpMB[$iCount] & '"')
            FileWriteLine($MBFile2, '$MsgBoxLine' & $iCount & ' = "' & $SSpMB[$iCount] & '"')
            If $iCount < UBound($SSpMB) - 1 Then
                $LinesToShow &= '$MsgBoxLine' & $iCount & ' & @CRLF & '
            Else
                $LinesToShow &= '$MsgBoxLine' & $iCount
            EndIf
        Next
        
        Local $MBLine3 = 'WinWait("' & $MBTitle & '", ' & '$LinesToShow' & ')'
        Local $MBLine4 = 'WinMove("' & $MBTitle & '", ' & '$LinesToShow' & ', ' & $MBxPos & ', ' & $MByPos & ')'
        FileWriteLine($MBFile, '$LinesToShow = ' & $LinesToShow & @CRLF & $MBLine3 & @CRLF & $MBLine4)
        FileWriteLine($MBFile2, '$LinesToShow = ' & $LinesToShow)
        
        Local $MsgBoxLine2 = '$MsgBoxValue = MsgBox(' & $MBFlag & ', ''' & $MBTitle & ''', ' & '$LinesToShow' & ', ''' & $MBTimeOut & ''')'
        Local $MsgBoxLine3 = 'ConsoleWrite(' & "'MsgBoxSays'" & ' & $MsgBoxValue & ' & "'Return'" & ')'
        FileWriteLine($MBFile2, $MsgBoxLine2 & @CRLF & $MsgBoxLine3)
        FileClose($MBFile)
        FileClose($MBFile2)
    Else
        Local $MBLine1 = '#NoTrayIcon'
;Local $MBLine3 = 'WinWait("' & $MBTitle & '", "' & $MBText & '")'
        Local $MBLine2 = 'While 1'
        Local $MBLine3 = '  If WinExists("' & $MBTitle & '", "' & $MBText & '"' & ') Then'
        Local $MBLine4 = '      While WinExists("' & $MBTitle & '", "' & $MBText & '"' & ')'
        Local $MBLine5 = '          WinMove("' & $MBTitle & '", "' & $MBText & '"' & ', ' & $MBxPos & ', ' & $MByPos & ')'
        Local $MBLine6 = '          $WinPos = WinGetPos("' & $MBTitle & '", "' & $MBText & '")'
        Local $MBLine7 = '          If IsArray($WinPos) And $WinPos[0] = ' & $MBxPos & ' And $WinPos[1] = ' & $MByPos & ' Then Exit'
        Local $MBLine8 = '      WEnd'
        Local $MBLine9 = '  EndIf'
        Local $MBLine10 = 'WEnd'
        FileWrite($MBFile, $MBLine1 & @CRLF & _
                $MBLine2 & @CRLF & _
                $MBLine3 & @CRLF & _
                $MBLine4 & @CRLF & _
                $MBLine5 & @CRLF & _
                $MBLine6 & @CRLF & _
                $MBLine7 & @CRLF & _
                $MBLine8 & @CRLF & _
                $MBLine9 & @CRLF & _
                $MBLine10)
        FileClose($MBFile)
        
        Local $MsgBoxLine1 = '#NoTrayIcon'
        Local $MsgBoxLine2 = '$MsgBoxValue = MsgBox(' & $MBFlag & ', ''' & $MBTitle & ''', ''' & $MBText & ''', ''' & $MBTimeOut & ''')'
        Local $MsgBoxLine3 = 'ConsoleWrite(' & "'MsgBoxSays'" & ' & $MsgBoxValue & ' & "'Return'" & ')'
        FileWrite($MBFile2, $MsgBoxLine1 & @CRLF & $MsgBoxLine2 & @CRLF & $MsgBoxLine3)
        FileClose($MBFile2)
    EndIf
    
    $MBPID1 = Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\MiscMMB.txt")
    $MBPID2 = Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & EnvGet("temp") & "\MiscMMB2.txt", @WorkingDir, 0, 6)
    
    WinWait($MBTitle, $MBText, 2)
    While (Not FileDelete(EnvGet("temp") & "\MiscMMB.txt") Or Not FileDelete(EnvGet("temp") & "\MiscMMB2.txt"))
        Sleep(10)
    WEnd
    
    If $MBContinue Then
        While 1
            $StdOutReadValue = StdoutRead($MBPID2)
            If StringInStr($StdOutReadValue, 'MsgBoxSays') Then
                $a_Array = StringRegExp($StdOutReadValue, '(?:MsgBoxSays)(.*?)(?:Return)', 3)
                If Not @error Then Return $a_Array[0]
                Return 0
            EndIf
            Sleep(10)
        WEnd
    EndIf
    Return 0
EndFunc ;==>_MoveMsgBox
Edited 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.

Link to comment
Share on other sites

...Here's an example, this should fix any issue you are having with a slow computer:

Nope, same problem. The only problem line was (and still is) this line: WinWait($MBTitle, $MBText, 2)

If you change it to a much longer timeout, then the temp files will not be deleted before they can be loaded into memory: WinWait($MBTitle, $MBText, 2000)

The Anti-Virus setting that I was messing with is a cache where it keeps track of apps deemed safe. If I disable that cache, then it took much more than 2 seconds for the temp files to be loaded into RAM. You can remark out that line and see what I mean by the files being deleted too soon.

No problem with the .xxx ext.

It does point out that most any or no ext. can be used.

(I noticed/changed the MsgBox flag to a boring 4.)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • Moderators

Nope, same problem. The only problem line was (and still is) this line: WinWait($MBTitle, $MBText, 2)

If you change it to a much longer timeout, then the temp files will not be deleted before they can be loaded into memory: WinWait($MBTitle, $MBText, 2000)

The Anti-Virus setting that I was messing with is a cache where it keeps track of apps deemed safe. If I disable that cache, then it took much more than 2 seconds for the temp files to be loaded into RAM. You can remark out that line and see what I mean by the files being deleted too soon.

No problem with the .xxx ext.

It does point out that most any or no ext. can be used.

(I noticed/changed the MsgBox flag to a boring 4.)

Sorry the WinWait() timeout was for testing was for testing. I also fixed the line breaks of text with a While/WEnd
$xpos = 50
$ypos = 30
$TestValue = _MoveMsgBox(68, "Testing Move MsgBox", 'Would you like to continue?' & @CRLF & 'If you would like to continue click Yes, otherwise press No', 0, $xpos, $ypos, 1)

If $TestValue = 6 Then
    MsgBox(64, 'Info:', 'You Chose Yes')
ElseIf $TestValue = 7 Then
    MsgBox(64, 'Info:', 'You Chose No')
Else
    MsgBox(48, 'Error:', 'Something is wrong with the return values')
EndIf

Func _MoveMsgBox($MBFlag, $MBTitle, $MBText, $MBTimeOut, $MBxPos, $MByPos, $MBContinue = 0)
    Local $MBFile = FileOpen(EnvGet("temp") & "\MiscMMB.txt", 2)
    Local $MBFile2 = FileOpen(EnvGet("temp") & "\MiscMMB2.txt", 2)
    If $MBFile = -1 Or $MBFile2 = -1 Then Return 0
    
    Local $LineDelimter = '', $MBPID1 = '', $MBPID2 = ''
    
    If UBound(StringSplit($MBText, @CRLF, 1)) - 2 > 0 Then
        $LineDelimter = @CRLF
    ElseIf UBound(StringSplit($MBText, @CR, 1)) - 2 > 0 Then
        $LineDelimter = @CR
    ElseIf UBound(StringSplit($MBText, @LF, 1)) - 2 > 0 Then
        $LineDelimter = @LF
    EndIf
    
    Local $SSpMB = StringSplit($MBText, $LineDelimter, 1)
    If UBound($SSpMB) - 2 > 0 And $LineDelimter <> '' Then
        Local $MBLine1 = '#NoTrayIcon'
        FileWriteLine($MBFile, $MBLine1)
        
        $MsgBoxLine1 = '#NoTrayIcon'
        FileWriteLine($MBFile2, $MsgBoxLine1)
        
        Local $MsgBoxLine[UBound($SSpMB)]
        Local $LinesToShow = ''
        For $iCount = 1 To UBound($SSpMB) - 1
            FileWriteLine($MBFile, '$MsgBoxLine' & $iCount & ' = "' & $SSpMB[$iCount] & '"')
            FileWriteLine($MBFile2, '$MsgBoxLine' & $iCount & ' = "' & $SSpMB[$iCount] & '"')
            If $iCount < UBound($SSpMB) - 1 Then
                $LinesToShow &= '$MsgBoxLine' & $iCount & ' & @CRLF & '
            Else
                $LinesToShow &= '$MsgBoxLine' & $iCount
            EndIf
        Next

        Local $MBLine2 = 'While 1'
        Local $MBLine3 = '    If WinExists("' & $MBTitle & '", ' & '$MsgBoxLine1' & ') Then'
        Local $MBLine4 = '        While WinExists("' & $MBTitle & '", ' & '$MsgBoxLine1' & ')'
        Local $MBLine5 = '            ControlMove("' & $MBTitle & '", ' & '$MsgBoxLine1' & ', "", ' & $MBxPos & ', ' & $MByPos & ')'
        Local $MBLine6 = '            $WinPos = WinGetPos("' & $MBTitle & '", ' & '$MsgBoxLine1' & ')'
        Local $MBLine7 = '            If IsArray($WinPos) And $WinPos[0] = ' & $MBxPos & ' And $WinPos[1] = ' & $MByPos & ' Then Exit'
        Local $MBLine8 = '        WEnd'
        Local $MBLine9 = '    EndIf'
        Local $MBLine10 = 'WEnd'
        FileWrite($MBFile, '$LinesToShow = ' & $LinesToShow & @CRLF & _
                $MBLine2 & @CRLF & _
                $MBLine3 & @CRLF & _
                $MBLine4 & @CRLF & _
                $MBLine5 & @CRLF & _
                $MBLine6 & @CRLF & _
                $MBLine7 & @CRLF & _
                $MBLine8 & @CRLF & _
                $MBLine9 & @CRLF & _
                $MBLine10)
        FileWriteLine($MBFile2, '$LinesToShow = ' & $LinesToShow)
        
        Local $MsgBoxLine2 = '$MsgBoxValue = MsgBox(' & $MBFlag & ', ''' & $MBTitle & ''', ' & '$LinesToShow' & ', ''' & $MBTimeOut & ''')'
        Local $MsgBoxLine3 = 'ConsoleWrite(' & "'MsgBoxSays'" & ' & $MsgBoxValue & ' & "'Return'" & ')'
        FileWriteLine($MBFile2, $MsgBoxLine2 & @CRLF & $MsgBoxLine3)
        FileClose($MBFile)
        FileClose($MBFile2)
    Else
        Local $MBLine1 = '#NoTrayIcon'
        ;Local $MBLine3 = 'WinWait("' & $MBTitle & '", "' & $MBText & '")'
        Local $MBLine2 = 'While 1'
        Local $MBLine3 = '    If WinExists("' & $MBTitle & '", "' & $MBText & '"' & ') Then'
        Local $MBLine4 = '        While WinExists("' & $MBTitle & '", "' & $MBText & '"' & ')'
        Local $MBLine5 = '            ControlMove("' & $MBTitle & '", "' & $MBText & '"' & ', "", ' & $MBxPos & ', ' & $MByPos & ')'
        Local $MBLine6 = '            $WinPos = WinGetPos("' & $MBTitle & '", "' & $MBText & '")'
        Local $MBLine7 = '            If IsArray($WinPos) And $WinPos[0] = ' & $MBxPos & ' And $WinPos[1] = ' & $MByPos & ' Then Exit'
        Local $MBLine8 = '        WEnd'
        Local $MBLine9 = '    EndIf'
        Local $MBLine10 = 'WEnd'
        FileWrite($MBFile, $MBLine1 & @CRLF & _
                $MBLine2 & @CRLF & _
                $MBLine3 & @CRLF & _
                $MBLine4 & @CRLF & _
                $MBLine5 & @CRLF & _
                $MBLine6 & @CRLF & _
                $MBLine7 & @CRLF & _
                $MBLine8 & @CRLF & _
                $MBLine9 & @CRLF & _
                $MBLine10)
        FileClose($MBFile)
        
        Local $MsgBoxLine1 = '#NoTrayIcon'
        Local $MsgBoxLine2 = '$MsgBoxValue = MsgBox(' & $MBFlag & ', ''' & $MBTitle & ''', ''' & $MBText & ''', ''' & $MBTimeOut & ''')'
        Local $MsgBoxLine3 = 'ConsoleWrite(' & "'MsgBoxSays'" & ' & $MsgBoxValue & ' & "'Return'" & ')'
        FileWrite($MBFile2, $MsgBoxLine1 & @CRLF & $MsgBoxLine2 & @CRLF & $MsgBoxLine3)
        FileClose($MBFile2)
    EndIf
    
    $MBPID1 = Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\MiscMMB.txt")
    $MBPID2 = Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & EnvGet("temp") & "\MiscMMB2.txt", @WorkingDir, 0, 6)
    
    WinWait($MBTitle, $MBText, 60)
    While (Not FileDelete(EnvGet("temp") & "\MiscMMB.txt") Or Not FileDelete(EnvGet("temp") & "\MiscMMB2.txt"))
        Sleep(10)
    WEnd
    
    If $MBContinue Then
        While 1
            $StdOutReadValue = StdoutRead($MBPID2)
            If StringInStr($StdOutReadValue, 'MsgBoxSays') Then
                $a_Array = StringRegExp($StdOutReadValue, '(?:MsgBoxSays)(.*?)(?:Return)', 3)
                If Not @error Then Return $a_Array[0]
                Return 0
            EndIf
            Sleep(10)
        WEnd
    EndIf
    Return 0
EndFunc   ;==>_MoveMsgBox
I don't think it should be more than a minute to wait for it to load, really anything to much under the normal time to bring a message box up (Not 60 seconds) IMHO is not worth using this. Edited 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.

Link to comment
Share on other sites

Prompted by this request:

http://www.autoitscript.com/forum/index.ph...showtopic=26489

Edit: removed code - had errors... gafrost fixed them :-) Thanks!

@Others,

How can I allow the optional parms to be skipped without impacting the position of the InputBox?

$ans = _InputBoxOnTop("Title", "Prompt") will make a box at position 0, 0 instead of centered.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

; InputBox OnTop
; Author - herewasplato

$ans = _InputBoxOnTop("Title", "Prompt")
If @error = 0 Then MsgBox(0, "Returned", $ans)
If @error = 1 Then MsgBox(0, "", "The Cancel button was pushed.")
If @error = 2 Then MsgBox(0, "", "The Timeout time was reached.")
If @error = 3 Then MsgBox(0, "", "The InputBox failed to open.")

Func _InputBoxOnTop($IBTitle, $IBPrompt, $IBDefault = "", _
        $IBpassword_char = "", $IBWidth = -1, $IBHeight = -1, _
        $IBLeft = Default, $IBTop = Default, $IBTimeOut = "")
    Local $file = FileOpen(EnvGet("temp") & "\InputBoxOT.au3", 2)
    If $file = -1 Then Return;if error, give up
    
    Local $line1 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
    Local $line2 = 'WinWait("' & $IBTitle & '", "' & $IBPrompt & '")'
    Local $line3 = 'WinSetOnTop("' & $IBTitle & '", "' & $IBPrompt & '" ,1)'
    FileWrite($file, $line1 & @CRLF & $line2 & @CRLF & $line3)
    FileClose($file)
    
    Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\InputBoxOT.au3")
    
    Local $ans = InputBox($IBTitle, $IBPrompt, $IBDefault, _
            $IBpassword_char, $IBWidth, $IBHeight, _
            $IBLeft, $IBTop, $IBTimeOut)
    If @error Then
        $ans = @error
        While Not FileDelete(EnvGet("temp") & "\InputBoxOT.au3")
            Sleep(10)
        WEnd
        SetError($ans)
        $ans = ""
        Return $ans
    EndIf
    
    While Not FileDelete(EnvGet("temp") & "\InputBoxOT.au3")
        Sleep(10)
    WEnd
    
    Return ($ans)
EndFunc   ;==>_InputBoxOnTop

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 3 weeks later...

SmOke_N does it again with another good use of /AutoIt3ExecuteScript:

_MsgBoxChangeButtons

http://www.autoitscript.com/forum/index.ph...st&p=194809

or here

http://www.autoitscript.com/forum/index.ph...showtopic=27491

Edit: yet another version:

http://www.autoitscript.com/forum/index.php?showtopic=32275

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...