Jump to content
Sign in to follow this  

Change MsgBox buton text

Recommended Posts


I thought I would attempt to provide an easy way to change the button text of MsgBox with the following constraints:

- does not use GUI functions

- does not rely on a second script (neither an entirely separate script, nor FileWriteLine'd script, nor FileInstall'd script).

Requires latest AutoIt beta; should work on uncompiled and compiled scripts.

The following is designed to be Include'd (or inserted directly) at the very beginning of your program.


;Expects 2 to 5 command-line parameters:
;  Title of MsgBox to watch for
;  Text of MsgBox to watch for
;  Text to show for first button
;  Text to show for second button
;  Text to show for third button (if applicable)

; Wrap the body of the script in a function so as not to pollute global variable space...
; I also chose a function name that should not conflict with 
Func __Do_Main()
   Local $numArgs = $CmdLine[0]
   If $numArgs < 2 Then Return
   Local $title = $CmdLine[1], $text = $CmdLine[2]
   Local $winWaitDelay = Opt("WinWaitDelay", 5)
   If $text = "" Then 
      WinWait($title, $text)
   Opt("WinWaitDelay", $winWaitDelay)
  ;I wonder if the If statements or For-loop is more efficient
  ;;If $numArgs > 2 Then ControlSetText($title, $text, "Button1", $CmdLine[3])
  ;;If $numArgs > 3 Then ControlSetText($title, $text, "Button2", $CmdLine[4])
  ;;If $numArgs > 4 Then ControlSetText($title, $text, "Button3", $CmdLine[5])
   For $i = 3 to $numArgs
      ControlSetText($title, $text, "Button" & ($i-2), $CmdLine[$i])

; The command you use to create custom MsgBox buttons
Func SetMsgBoxButtons($title, $text, $first = "", $second = "", $third = "")
   Local $cmd = '"' & @ScriptFullPath & '" "' & $title & '" "' & $text & '"'
   If @NumParams > 2 Then $cmd = $cmd & ' "' & $first & '"'
   If @NumParams > 3 Then $cmd = $cmd & ' "' & $second & '"'
   If @NumParams > 4 Then $cmd = $cmd & ' "' & $third & '"'
   If @Compiled Then
      Return Run($cmd, "", @SW_HIDE)
      Local $AutoIt = RegRead("HKLM\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\AutoIt3.exe"
      If FileExists($AutoIt) Then Return Run('"' & $AutoIt & '" ' & $cmd, "", @SW_HIDE)

Example usage. Notice that you call SetMsgBoxButtons before the MsgBox. That's all folks!

#include "MsgBoxInc.au3"
Opt("TrayIconHide", 0);show tray icon

$title = "Example"
$text = "What do you think?"

SetMsgBoxButtons($title, $text, "Good", "Fair", "Poor")
MsgBox(4099, $title, $text)

SetMsgBoxButtons($title, "Second Example", "Okay!")
MsgBox(4096, $title, "Second Example")


  • Scripts that rely on command-line paramters would need to be modified...
  • SetMsgBoxButtons does not like an empty text paramter
  • There is a slight delay before the button text is updated, so the old text can be seen for a split second

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post

Link to post
Share on other sites

U Da Man CS!

Edited by sykes

We have enough youth. How about a fountain of SMART?

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.