Sign in to follow this  
Followers 0
ChrisL

Move msgbox and change the buttons

3 posts in this topic

#1 ·  Posted (edited)

This is a merge of 2 UDF's to chang the text on msgbox buttons and also to move the message box to a location on the screen

;===============================================================================
;
;~ Function: _MsgBoxChangeButtons()
;~ Desctiption Changes the position of and button text of a MsgBox()
;~ Version: N/A
;~ Original UDF's HerewasPlato and Smoke_N
;~ Author: ChrisL
;~ Parameter(s): 
;~ $iMBFlag = Icon and or Flags (Type of buttons)
;~ $MBTitle = Title of MsgBox()
;~ $MBText = Text for the Body of the MsgBox()
;~ $MBButton1 = Text to change the first button
;~ $MBButton2 = Optional Param: Text to change the second Button if applicable
;~ $MBButton3 = Optional Param: Text to change the third Button if applicable
;~ $iMBTimeOut = Optional Param: MsgBox() Time out
;~ $xMBpos = Optional Param: X coordinate to move to. Default no move is ""
;~ $yMBpos = Optional Param: y coordinate to move to. Default no move is ""
;~ Requirement(s): AutoIt Beta 3.1xx
;~ Example:
;~ _MsgBoxChangeButtons(36, 'My Title', 'My Text', 'Button 1', 'Button 2', '', 3,100,20)
;~ Example Result: Will turn out a MsgBox() instead of Yes and No button will be Button 1 and Button 2 with a time out of 3 seconds at x 100 and y 20
;~ Return Value(s): Will return the value that was clicked in the MsgBox()
;~ Return Value -1 incorrect parameter see @error for details
;~ @error 1 $iFlag is not numerical
;~ @error 2 $iMBTimeOut is not numerical
;~ @error 3 $xMBpos is not numerical
;~ @error 4 $yMBpos is not numerical
;
;===============================================================================


Func _MsgBoxChangeButtons($iFlag, $sTitle, $sText, $sButton1, $sButton2 = '', $sButton3 = '', $iMBTimeOut = 0, $xMBpos = "", $yMBpos = "")
    If Not IsNumber ($iFlag) then 
        Seterror (1 )
        Return -1
    ElseIf Not IsNumber ($iMBTimeOut) then 
        Seterror (2 )
        Return -1
    ElseIf $xMBpos <> "" and IsNumber ($xMBpos) = 0 then 
        Seterror (3 )
        Return -1
    ElseIf $yMBpos <> "" and IsNumber ($yMBpos) = 0 then 
        Seterror (4 )
        Return -1
        Endif
    
    Local $MBFile = FileOpen(@TempDir & '\MiscMMB.txt', 2)
    Local $MBLine0 = ''
    Local $MBLine1 = '#NoTrayIcon'
    Local $MBLine2 = 'Opt("WinWaitDelay", 0)'
    Local $MBLine3 = 'WinWait("' & $sTitle & '")'
    Local $MBLine4 = 'ControlSetText("' & $sTitle & '", "", "Button1", "' & $sButton1 & '")'
    Local $MBLine5 = 'ControlSetText("' & $sTitle & '", "", "Button2", "' & $sButton2 & '")'
    Local $MBLine6 = 'ControlSetText("' & $sTitle & '", "", "Button3", "' & $sButton3 & '")'
    Local $MBline7 = 'WinMove("' & $sTitle & '", ""' & ', ' & $xMBpos & ', ' & $yMBpos & ')'
    Local $MBline8 = '$pos = WingetPos("' & $sTitle & '", "")'
    Local $MBline9 = 'WinMove("' & $sTitle & '", ""' & ', ' & $xMBpos & ',$pos[1])'
    Local $MBline10 = 'WinMove("' & $sTitle & '", ""' & ', $pos[0], ' & $yMBpos & ')'
    If $sButton2 = '' Then
        FileWrite(@TempDir & '\MiscMMB.txt',$MBLine0 & @crlf & $MBLine1 & @CRLF & $MBLine2 & @CRLF & $MBLine3 & @CRLF & $MBLine4)
    ElseIf $sButton2 <> '' And $sButton3 = '' Then
        FileWrite(@TempDir & '\MiscMMB.txt',$MBLine0 & @crlf & $MBLine1 & @CRLF & $MBLine2 & _
            @CRLF & $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5)
    ElseIf $sButton2 <> '' And $sButton3 <> '' Then
        FileWrite(@TempDir & '\MiscMMB.txt',$MBLine0 & @crlf & $MBLine1 & @CRLF & $MBLine2 & @CRLF & _
            $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5 & @CRLF & $MBLine6)
    EndIf
        If $xMBpos <> "" and $yMBpos <> "" then
        FileWriteLine(@TempDir & '\MiscMMB.txt', @crlf & $MBLine7)
        ElseIf $xMBpos <> "" and $yMBpos = "" then
            FileWriteLine (@TempDir & '\MiscMMB.txt', @crlf & $MBLine8)
            FileWriteLine (@TempDir & '\MiscMMB.txt', @crlf & $MBLine9)
        Elseif $xMBpos = "" and $yMBpos <> "" then
            FileWriteLine (@TempDir & '\MiscMMB.txt', @crlf & $MBLine8)
            FileWriteLine (@TempDir & '\MiscMMB.txt', @crlf & $MBLine10)
            Endif
            
        
    $MBPID1 = Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & EnvGet('TEMP') & '\MiscMMB.txt')
    $MBBox = MsgBox($iFlag, $sTitle, $sText, $iMBTimeOut)
    FileClose($MBFile)
    Do
        FileDelete(@TempDir & '\MiscMMB.txt')
    Until Not FileExists(@TempDir & '\MiscMMB.txt')
    Return $MBBox
EndFunc

Herewasplato's UDF http://www.autoitscript.com/forum/index.php?showtopic=22531

Smoke_N's UDF http://www.autoitscript.com/forum/index.php?showtopic=27491

Edit

Changed the -1 param to "" and added some @errors if Letters are used instead of numbers in the numerical parameters

Edited by ChrisL

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
Sign in to follow this  
Followers 0