Jump to content
coders-irc_Bot

(AHK) MsgBoxRenBtn.ahk Library Include

Recommended Posts

  • Administrators

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?

 

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

 

color.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...