Sign in to follow this  
Followers 0
SmOke_N

MsgBox - Change Button Names

29 posts in this topic

#1 ·  Posted (edited)

From a request in the support forum.

If you have only one button, you can send $sCIDChange just the text you want to change it to, or if your using more than one button, you can send it an array in the order you want the buttons to be changed to the text you want to change them.

Local $ChangeText[4] = ['', 'Enable', 'Disable', 'Quit']
$iMsg = _MsgBoxEx(3, 'nothing', 'something', 0, $ChangeText)
MsgBox(64, 'Info', 'The Return Was: ' & $iMsg)

Func _MsgBoxEx($iFlag, $sTitle, $sText, $iTime = 0, $sCIDChange = '')
    Local $_MsgBox_ = '"' & "ConsoleWrite(MsgBox(" & $iFlag & ', ""' & $sTitle & '"", ""' & $sText & '"", ' & $iTime & '"))'
    Local $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $_MsgBox_, '', @SW_SHOW, 6)
    Do
        Sleep(10)
    Until WinExists($sTitle)
    If IsArray($sCIDChange) Then
        For $iCC = 1 To UBound($sCIDChange) - 1
            ControlSetText($sTitle, '', 'Button' & $iCC, $sCIDChange[$iCC])
        Next
    Else
        ControlSetText($sTitle, '', 'Button1', $sCIDChange)
    EndIf
    While ProcessExists($iPID)
        Local $iStdOut = StdoutRead($iPID)
        If Number($iStdOut) Then Return $iStdOut
        Sleep(10)
    WEnd
    If IsArray($sCIDChange) Then Return SetError(1, 0, 2)
    Return SetError(1, 0, 1)
EndFunc

Edit:

Suggestion on time out from MHz :P

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites



You spelt "Disable" wrong. Lol, other than that, nice work once again Smoke :P


- Dan [Website]

Share this post


Link to post
Share on other sites

Nice simple idea SmOke

You can also add some accellerator keys to it

Global $ChangeText[4] = ['', '&Enable', '&Disble', '&Quit']

How do you tell the difference between a timeout and quit though as they both return 2?

(Ah, your loop code is blocking any result <= 0 :P )

Share this post


Link to post
Share on other sites

Very Cool!

:P

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You spelt "Disable" wrong. Lol, other than that, nice work once again Smoke :)

Nit picking will get you every where :nuke:

No biggie, at least you see the error! :D

Nice simple idea SmOke

You can also add some accellerator keys to it

Global $ChangeText[4] = ['', '&Enable', '&Disble', '&Quit']

How do you tell the difference between a timeout and quit though as they both return 2?

(Ah, your loop code is blocking any result <= 0 :P )

I couldn't figure that out really on timeout with a "short" version, I only spent 20+ minutes on it... and haven't looked back since.

Edit:

I now remember that I treated a time out like a cancel... I never bothered to see what an "actual" timeout returned.... so I guess I can do that mananna.

Edit2:

Guess you could always put this below the WEnd

If $iStdOut = - 1 Then Return SetError(1, 0, -1)

I'll make the change...

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I thought I gave a good enough hint of the problem? :nuke:

Global $ChangeText[4] = ['', '&Enable', '&Disble', '&Quit']
$iMsg = _MsgBoxEx(3, 'nothing', 'something', 2, $ChangeText)
MsgBox(64, 'Info', 'The Return Was: ' & $iMsg)

Func _MsgBoxEx($iFlag, $sTitle, $sText, $iTimeout = 0, $sCIDChange = '')
    Local $_MsgBox_ = '"' & "ConsoleWrite(MsgBox(" & $iFlag & ', ""' & $sTitle & '"", ""' & $sText & '"", ' & $iTimeout & '"))'
    Local $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $_MsgBox_, '', @SW_SHOW, 6)
    Do
        Sleep(10)
    Until WinExists($sTitle)
    If IsArray($sCIDChange) Then
        For $iCC = 1 To UBound($sCIDChange) - 1
            ControlSetText($sTitle, '', 'Button' & $iCC, $sCIDChange[$iCC])
        Next
    Else
        ControlSetText($sTitle, '', 'Button1', $sCIDChange)
    EndIf
    While ProcessExists($iPID)
        Local $iStdOut = StdoutRead($iPID)
        If Number($iStdOut) Then Return $iStdOut ; Notice something different?
        Sleep(10)
    WEnd
    If IsArray($sCIDChange) Then Return SetError(1, 0, 2)
    Return SetError(1, 0, 1)
EndFunc

-1 is <= 0 so the condition was never met in your loop and so when timed out (ProcessExists condition finished), it would go down to to the If IsArray()... line and Return 2 for timeout. :P

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I thought I gave a good enough hint of the problem? :)

-1 is <= 0 so the condition was never met in your loop and so when timed out (ProcessExists condition finished), it would go down to to the If IsArray()... line and Return 2 for timeout. :P

I'm not all here at the moment, but the "fix" (my earlier edit) I attempted seemed to work without everything else ... is there an error in it that my not so keen eyes aren't seeing?

If the function timed out, the first thing it does is check to see if the value is -1 for timeout ... something else I'm missing? Like I said, I don't use the timeout function much... actually at all, but I may have missed something that I'm not understanding from your suggestion... or did you not see the fix?.

Edit:

Ahh, I did notice the difference... (in you ;Notice something different) (keen eyes :nuke: )... that's a good point.

Saves me a line and has the same effect.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

:P You could even add a text item when $iTime is non-zero, that says "Auto close in: xx" and update it in the ProcessExists loop .. or maybe a scroll bar if you can add one with the GUI (sorry, my GUI expertise is very green still).

I'll send an example as soon as i get some time to play around with it some more

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

:P You could even add a text item when $iTime is non-zero, that says "Auto close in: xx" and update it in the ProcessExists loop .. or maybe a scroll bar if you can add one with the GUI (sorry, my GUI expertise is very green still).

I'll send an example as soon as i get some time to play around with it some more

I like that idea, please do!

Edit:

P.S.... That's sounds like an AnyGUI.au3 Add on to me, the other controls are pretty much taken up unless you did the count down on an existing control?

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Edit:

Ahh, I did notice the difference... (in you ;Notice something different) (keen eyes :P )... that's a good point.

Saves me a line and has the same effect.

Touchẽ

Here is a few more lines saved. See the difference?

Global $ChangeText[4] = ['', '&Enable', '&Disble', '&Quit']
$iMsg = _MsgBoxEx(3, 'nothing', 'something', 0, $ChangeText)
MsgBox(64, 'Info', 'The Return Was: ' & $iMsg)

Func _MsgBoxEx($iFlag, $sTitle, $sText, $iTimeout = 0, $sCIDChange = '')
    Local $_MsgBox_ = '"' & "ConsoleWrite(MsgBox(" & $iFlag & ', ""' & $sTitle & '"", ""' & $sText & '"", ' & $iTimeout & '"))'
    Local $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $_MsgBox_, '', @SW_SHOW, 6)
    Do
        Sleep(10)
    Until WinExists($sTitle)
    If IsArray($sCIDChange) Then
        For $iCC = 1 To UBound($sCIDChange) - 1
            ControlSetText($sTitle, '', 'Button' & $iCC, $sCIDChange[$iCC])
        Next
    Else
        ControlSetText($sTitle, '', 'Button1', $sCIDChange)
    EndIf
    Local $iStdOut = StdoutRead($iPID) ; waiting...
    If Number($iStdOut) Then Return $iStdOut
    If IsArray($sCIDChange) Then Return SetError(1, 0, 2)
    Return SetError(1, 0, 1)
EndFunc

:nuke:

Share this post


Link to post
Share on other sites

Never thought you could continueously catch stdoutread without a loop.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Never thought you could continueously catch stdoutread without a loop.

I believe the logic is the buffer never gets full so StdoutRead() idles and waits. Anyhow, I do like trids idea, so if it is feasible, then an addition sounds nice. :P

Share this post


Link to post
Share on other sites

I believe the logic is the buffer never gets full so StdoutRead() idles and waits. Anyhow, I do like trids idea, so if it is feasible, then an addition sounds nice. :nuke:

Damn StdoutRead() catches it and doesn't allow me to change anything :P (Glad you showed that above, I'd have been pissed trying to figure it out).

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

something for you to chew on smoke

Global $ChangeText[4] = ['', '&Enable', '&Disble', '&Quit']
$iMsg = _MsgBoxEx(3, 'nothing', 'something', 10, $ChangeText)
MsgBox(64, 'Info', 'The Return Was: ' & $iMsg)

Func _MsgBoxEx($iFlag, $sTitle, $sText, $iTimeout = 0, $sCIDChange = '')
    Local $_MsgBox_ = '"' & "ConsoleWrite(MsgBox(" & $iFlag & ', ""' & $sTitle & '"", ""' & $sText & '"", ' & $iTimeout & '"))'
    Local $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $_MsgBox_, '', @SW_SHOW, 6)
    Do
        Sleep(10)
    Until WinExists($sTitle)
    If IsArray($sCIDChange) Then
        For $iCC = 1 To UBound($sCIDChange) - 1
            ControlSetText($sTitle, '', 'Button' & $iCC, $sCIDChange[$iCC])
        Next
    Else
        ControlSetText($sTitle, '', 'Button1', $sCIDChange)
    EndIf
    If $iTimeout Then _CountDown($sTitle, $iTimeout, $iPID)
    Local $iStdOut = StdoutRead($iPID) ; waiting...
    If Number($iStdOut) Then Return $iStdOut
    If IsArray($sCIDChange) Then Return SetError(1, 0, 2)
    Return SetError(1, 0, 1)
EndFunc   ;==>_MsgBoxEx

Func _CountDown($sTitle, $iTimeout, $iPID)
    Local $orig_title = $sTitle
    Local $newTitle = $sTitle & " Time out in " & $iTimeout
    WinSetTitle($sTitle, "", $newTitle)
    $sTitle = $newTitle
    Local $now = @SEC
    Local $end = @SEC + $iTimeout
    While Not Number(StdoutRead($iPID, 2, True))
        Sleep(10)
        If $now <> @SEC Then
            $now = @SEC
            $newTitle = $orig_title & " Time out in " & $end - $now
            WinSetTitle($sTitle, "", $newTitle)
            $sTitle = $newTitle
        EndIf
    WEnd
EndFunc   ;==>_CountDown

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

I won't Chew too much, might get fatter!

Gary, counter is messed up it seems, went to 1 then 62/61...

I was reading up on stdoutread() and it's parameters to better understand it, thanks for the "True"...

With that in mind, before the battle there for myself, was anyone able to change the static1/2 fields rather than the title bar?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I won't Chew too much, might get fatter!

Gary, counter is messed up it seems, went to 1 then 62/61...

I was reading up on stdoutread() and it's parameters to better understand it, thanks for the "True"...

With that in mind, before the battle there for myself, was anyone able to change the static1/2 fields rather than the title bar?

What did you put for the time out?


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

was anyone able to change the static1/2 fields rather than the title bar?

not yet .. but i seem to recall something clever that Larry once did to the Start -> Run dialog, which included adding elements to the window .. that was where i was aiming :P

Share this post


Link to post
Share on other sites

What did you put for the time out?

Copy and pasted yours... 10 I believe...

not yet .. but i seem to recall something clever that Larry once did to the Start -> Run dialog, which included adding elements to the window .. that was where i was aiming :P

Hmm... I'm assuming that would need to be done on every PC?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Copy and pasted yours... 10 I believe...

Hmm... I'm assuming that would need to be done on every PC?

Not getting that on my system, but i'll let you play around with the count, why not just use the Static1 that is already there i.e.

Global $ChangeText[4] = ['', '&Enable', '&Disble', '&Quit']
$iMsg = _MsgBoxEx(35, 'nothing', 'something', 10, $ChangeText)
MsgBox(64, 'Info', 'The Return Was: ' & $iMsg)

Func _MsgBoxEx($iFlag, $sTitle, $sText, $iTimeout = 0, $sCIDChange = '')
    Local $Static = "Static1"
    
    If BitAND($iFlag, 16) Or BitAND($iFlag, 32) Or BitAND($iFlag, 48) Or BitAND($iFlag, 64) Then $Static = "Static2"
    Local $_MsgBox_
    If $iTimeout Then
        $_MsgBox_ = '"' & "ConsoleWrite(MsgBox(" & $iFlag & ', ""' & $sTitle & '"", ""' & $sText & @LF & @LF & @LF & '"", ' & $iTimeout & '"))'
    Else
        $_MsgBox_ = '"' & "ConsoleWrite(MsgBox(" & $iFlag & ', ""' & $sTitle & '"", ""' & $sText & '"", ' & $iTimeout & '"))'
    EndIf
    Local $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $_MsgBox_, '', @SW_SHOW, 6)
    Do
        Sleep(10)
    Until WinExists($sTitle)
    If IsArray($sCIDChange) Then
        For $iCC = 1 To UBound($sCIDChange) - 1
            ControlSetText($sTitle, '', 'Button' & $iCC, $sCIDChange[$iCC])
        Next
    Else
        ControlSetText($sTitle, '', 'Button1', $sCIDChange)
    EndIf
    If $iTimeout Then _CountDown($sTitle, $sText, $iTimeout, $iPID, $Static)
    Local $iStdOut = StdoutRead($iPID) ; waiting...
    If Number($iStdOut) Then Return $iStdOut
    If IsArray($sCIDChange) Then Return SetError(1, 0, 2)
    Return SetError(1, 0, 1)
EndFunc   ;==>_MsgBoxEx

Func _CountDown($sTitle, $sText, $iTimeout, $iPID, $Static)
    Local $orig_text = $sText, $now = -999, $now = @SEC
    ControlSetText($sTitle, "", $Static, $orig_text & @LF & @LF & "Time out in " & $iTimeout & " Second(s)!!!", 1)
    While Not Number(StdoutRead($iPID, 2, True))
        If $now <> @SEC Then
            $iTimeout -= 1
            $now = @SEC
            If $iTimeout Then ControlSetText($sTitle, "", $Static, $orig_text & @LF & @LF & "Time out in " & $iTimeout & " Second(s)!!!", 1)
        EndIf
        Sleep(10)
    WEnd
EndFunc   ;==>_CountDown

Edit: fixed it to work with and without icon flag

Edit: condensed a few lines, probably can be condensed some more.

Edit: fixed counter

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Would have to make sure there isn't an Icon ... if there is an icon, it would be static2.

Easy enough to fix, but the simple idea is getting a tad larger now :P


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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  
Followers 0