Hi everybody
I needed to display a couple of MsgBox with altered buttons captions.
Here is the way I just scripted it, using Timers (thanks to @KaFu for the idea, a few months ago)
#include <MsgBoxConstants.au3>
#include <WinAPISysWin.au3>
Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration
Global $g_aCaption, $g_sTitle ; 2 global variables for _TimerProc()
Dim $g_aCaption[3] = ["Hello", "How", "Are You ?"] ; 3 buttons (max) in MsgBox (not counting the 4th special button $MB_HELP)
$g_sTitle = "This is MsgBox #1"
Local $iChoice1 = _MsgBox(BitOr($MB_YESNOCANCEL, $MB_DEFBUTTON3, $MB_TOPMOST, $MB_ICONQUESTION), $g_sTitle, _
"1st line of text" & @crlf & "2nd line of text")
; ConsoleWrite("A: " & $iChoice1 & @crlf)
Dim $g_aCaption[2] = ["Copy text", "Ok"] ; 2 buttons
$g_sTitle = "This is MsgBox #2"
Local $iChoice2 = _MsgBox(BitOr($MB_OKCANCEL, $MB_DEFBUTTON2, $MB_TOPMOST), $g_sTitle, _
"I need these 2 buttons captions in another script)") ; think of $MB_YESNO too (2 buttons without Esc allowed)
; ConsoleWrite("B: " & $iChoice2 & @crlf)
Dim $g_aCaption[1] = ["Hello !"] ; 1 button (not really useful but well...)
$g_sTitle = "This is MsgBox #3"
Local $iChoice3 = _MsgBox(BitOr($MB_OK, $MB_TOPMOST), $g_sTitle, _
"Revolution 9, such a strange song", 5) ; timaout 5s (returns -1 if timed out)
; ConsoleWrite("C: " & $iChoice3 & @crlf)
;===============================================
Func _MsgBox($iFlag, $g_sTitle, ByRef $sText, $iTimeOut = 0, $hWnd = 0)
Local $hTimerProc = DllCallbackRegister('_TimerProc', 'none', 'hwnd;uint;uint_ptr;dword')
Local $iTimerID = _WinAPI_SetTimer(0, 0, 10, DllCallbackGetPtr($hTimerProc))
Local $iChoice = MsgBox($iFlag, $g_sTitle, $sText, $iTimeOut, $hWnd)
_WinAPI_KillTimer(0, $iTimerID)
DllCallbackFree($hTimerProc)
Return $iChoice
EndFunc ;==>_MsgBox
;===============================================
Func _TimerProc($hWnd, $iMsg, $iTimerID, $iTime)
If WinActive($g_sTitle) Then
_WinAPI_KillTimer(0, $iTimerID)
If Ubound($g_aCaption) > 3 Then ReDim $g_aCaption[3]
For $i = 0 To Ubound($g_aCaption) - 1
ControlSetText($g_sTitle, "", "Button" & ($i + 1), $g_aCaption[$i])
Next
EndIf
EndFunc ;==>_TimerProc
If you guys got comments or improvements on this, please share your thoughts here, thanks !