(AHK) MsgBoxRenBtn.ahk Library Include

By raccoon on Sep 13, 2013

Message Box Rename Buttons by Raccoon on 12-Sept-2013
Allows you to rename the one, two or three buttons of a standard MsgBox dialog, without having to create your own custom GUI.
This script is written as a "Standard Library" and belongs in your AutoHotkey\Lib directory.
Note that this function gets called immediately PRIOR your MsgBox command.

Example Usage:
MsgBoxRenBtn("Red","Green","Blue")
MsgBox, 0x22, Pick one!, What is your favorite color?
Example

; MsgBoxRenBtn.ahk Library Include.
; This file belongs in the \Lib directory.

;*******************************************************************************
;*            Message Box Rename Buttons by Raccoon on 12-Sept-2013            *
;*                                                                             *
;*  Usage: (see examples at bottom)                                            *
;*  MsgBoxRenBtn(<"Text for Button 1">,["Optional Button 2"],["Optional 3"])   *
;*  MsgBox, <parameters>                                                       *
;*******************************************************************************

MsgBoxRenBtn(btn1="",btn2="",btn3="")
{ ; by Raccoon 12-Sept-2013
  Static sbtn1:="", sbtn2:="", sbtn3:="", i=0
  sbtn1 := btn1, sbtn2 := btn2, sbtn3 := btn3, i=0
  SetTimer, MsgBoxRenBtn, 1
  Return

  MsgBoxRenBtn:
  If (hwnd:=WinActive("ahk_class #32770")) {
    if (sbtn1)
      ControlSetText, Button1, % sbtn1, ahk_id %hwnd%
    if (sbtn2)
      ControlSetText, Button2, % sbtn2, ahk_id %hwnd%
    if (sbtn3)
      ControlSetText, Button3, % sbtn3, ahk_id %hwnd%
    SetTimer, MsgBoxRenBtn, Off
  }
  if (i >= 1000)
    SetTimer, MsgBoxRenBtn, Off
  i++
  Return
}
; *** End of Function ***

; --- Optional Sample Script. ---
If (A_ScriptName = "MsgBoxRenBtn.ahk") ; Show Demo
{
  ; Simple Example: Replace "OK" Button with "World".
  MsgBoxRenBtn("World")
  MsgBox, Hello

  ; Two Button Example: Yes/No replaced with Dogs/Cats.
  MsgBoxRenBtn("Dogs","Cats")
  MsgBox, 0x4, Pick one!, Which do you like best?
  IfMsgBox Yes
    TrayTip,, You chose Dogs!
  IfMsgBox No
    TrayTip,, You chose Cats!

  ; Three Button Example: Abort/Retry/Ignore replaced with Red/Green/Blue.
  ; Note: 0x2 is Abort/Retry/Ignore, add 0x20 for Icon Question, is 0x22.
  MsgBoxRenBtn("Red","Green","Blue")
  MsgBox, 0x22, Pick one!, What is your favorite color?
  IfMsgBox Abort
    TrayTip,, You chose Red!
  IfMsgBox Retry
    TrayTip,, You chose Green!
  IfMsgBox Ignore
    TrayTip,, You chose Blue!

  Sleep, 3000
}
; --- End of Optional Script Sample. ---

; End of MsgBoxRenBtn.ahk Library Include.

Comments

Sign in to comment.
raccoon   -  Sep 13, 2013

Screenshots

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.