pixelsearch Posted August 1 Share Posted August 1 (edited) 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) expandcollapse popup#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 ! Edited August 2 by pixelsearch minor improvement in pic with 2 buttons KaFu 1 Link to comment Share on other sites More sharing options...
funkey Posted August 5 Share Posted August 5 HookDlgBox.au3HookDlgBox Timeout.au3HookDlgBox Example.au3 Hi! I use hooks to do this task. BR funkey Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
lIlIIlIllIIIIlI Posted August 5 Share Posted August 5 Is the problem, with changing text on a msgbox button, ultimately that typical code execution is paused when the prompt for user input is displayed? Link to comment Share on other sites More sharing options...
argumentum Posted August 5 Share Posted August 5 On 8/1/2024 at 7:29 PM, pixelsearch said: I needed to display a couple of MsgBox with altered buttons captions. I made a UDF some time ago for that. 2 hours ago, lIlIIlIllIIIIlI said: ultimately that typical code execution is paused when the prompt for user input is displayed? Yes, is a MsgBox. You now have the ability to change the button text. That's all. For anything else, build a GUI and code at will. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
pixelsearch Posted August 5 Author Share Posted August 5 (edited) @funkey always great to hear from you. Thanks for sharing your alternate way to do it. @lIlIIlIllIIIIlI Yes, MsgBox is a blocking function with predefined captions & return values. That's why we can't get the handle of its window when displayed, in a simple way by using WinGetHandle ( "title" [, "text"] ) So if we want to use it with altered captions (instead of creating our own dialogue GUI) then we have to find ways to do it. Gladly with the help of these great people on the Forum, they show us it's possible. @argumentum thanks for the link Edited August 5 by pixelsearch argumentum 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now