Sign in to follow this  
Followers 0
EhJay

MsgBox Customized Anwsers

22 posts in this topic

Hi. I'm trying to make a script that will let you choose to shutdown or hibernate in X seconds.

This is what I've got.

$answer = MsgBox ( 3, "Shutdown or Hibernate?", "Press yes to shutdown and no to hibernate.")

If $answer = 6 Then
;sets time to wait in minutes.
    Sleep(1000*60*Number(InputBox("Wait 'x' minutes","Enter Time To Wait")))
;1 for shutdown, 64 for hibernate, 
    Shutdown(1)
EndIF

If $answer = 7 Then
;sets time to wait in minutes.
    Sleep(1000*60*Number(InputBox("Wait 'x' minutes","Enter Time To Wait")))
;1 for shutdown, 64 for hibernate, 
    Shutdown(64)
EndIf

If $answer = 2 Then
    Exit
EndIf

As you can see I have a msgbox that I've had to rig. Clicking yes = shutdown, no = hibernate.

Is there anyway I can set my msgbox to have the actual words on it instead of yes and no coorisponding to the action?

Thanks for the help.

Share this post


Link to post
Share on other sites



#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.6 Prototype

#include <GuiConstants.au3>

GuiCreate("Shutdown or Hibernate?", 208, 138,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Button_1 = GuiCtrlCreateButton("Shutdown", 10, 110, 70, 20)
$Button_2 = GuiCtrlCreateButton("Hibernate", 110, 110, 70, 20)
$Input_3 = GuiCtrlCreateInput("", 10, 80, 180, 20)
$Label_4 = GuiCtrlCreateLabel("Minutes until Shutdown or Hibernate?", 10, 50, 180, 20)
$Label_5 = GuiCtrlCreateLabel("Do you want to shutdown or to hibernate?", 10, 10, 180, 30)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button_1
            Sleep(1000*60* GUICtrlRead( $Input_3 ) )
            Shutdown(1)
        Case $Button_2
            Sleep(1000*60* GUICtrlRead( $Input_3 ) )
            Shutdown(64)
        Case Else
            ;;;
    EndSwitch
WEnd
#endregion --- GuiBuilder generated code End ---

:D


--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Share this post


Link to post
Share on other sites

:D

Huh? What's that? And you built that with some GuiBuilder? I tried running it... I got an error.

Share this post


Link to post
Share on other sites

1.

Are you using newest beta?

2.

If yes run it with scite with ALT + F5

3.

If 2. returns an error than post error message

The gui builder is included in Scite :D


--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Share this post


Link to post
Share on other sites

Ohh.. Beta... Ok I will go download it and let you know how I make out. Thank you very much sir.

Share this post


Link to post
Share on other sites

Np :D


--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Share this post


Link to post
Share on other sites

WOW! That's exactly what I wanted! Thank you! What did you use to make it? Because it looks like something else made it and not you. Am I correct?

Share this post


Link to post
Share on other sites

I made it myself but with Scite you can choose GUIbuilder under Tools

And there you can "form" the GUI you want. You just ahve to edit the names and the actions that you want to happen when button is clicked .P


--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Here is an example using the actual MsgBox()... there are a few parameters I think are pretty self explanitory, but if you have a question, just ask... If I don't answer it someone will

$MsgBoxValue = _MsgBoxChangeButtons(4, 'This is my msgbox', 'This' & @CRLF & 'Should' & @CRLF & 'Work', 'ReBoot', 'Continue')
If $MsgBoxValue = 6 Then MsgBox(0, 'Clicked', 'You clicked the ReBoot Button')

Func _MsgBoxChangeButtons($iFlag, $sTitle, $sText, $sButton1, $sButton2 = '', $sButton3 = '', $iMBTimeOut = 0)
    Local $MBFile = FileOpen(@TempDir & '\MiscMMB.txt', 2)
    Local $MBLine1 = 'While Not WinExists("' & $sTitle & '")'
    Local $MBLine2 = '    Sleep(10)'
    Local $MBLine3 = 'WEnd'
    Local $MBLine4 = 'ControlSetText("' & $sTitle & '", "", "Button1", "' & $sButton1 & '")'
    Local $MBLine5 = 'ControlSetText("' & $sTitle & '", "", "Button2", "' & $sButton2 & '")'
    Local $MBLine6 = 'ControlSetText("' & $sTitle & '", "", "Button3", "' & $sButton3 & '")'
    If $sButton2 = '' Then
        FileWrite(@TempDir & '\MiscMMB.txt', $MBLine1 & @CRLF & $MBLine2 & @CRLF & $MBLine3 & @CRLF & $MBLine4)
    ElseIf $sButton2 <> '' And $sButton3 = '' Then
        FileWrite(@TempDir & '\MiscMMB.txt', $MBLine1 & @CRLF & $MBLine2 & _
            @CRLF & $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5)
    ElseIf $sButton2 <> '' And $sButton3 <> '' Then
        FileWrite(@TempDir & '\MiscMMB.txt', $MBLine1 & @CRLF & $MBLine2 & @CRLF & _
            $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5 & @CRLF & $MBLine6)
    EndIf
    $MBPID1 = Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & EnvGet('TEMP') & '\MiscMMB.txt')
    $MBBox = MsgBox($iFlag, $sTitle, $sText, $iMBTimeOut)
    FileClose($MBFile)
    Do
        FileDelete(@TempDir & '\MiscMMB.txt')
    Until Not FileExists(@TempDir & '\MiscMMB.txt')
    Return $MBBox
EndFunc

Edit:

Changed a few things... won't affect last output.

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

Wow. This is really complicated. I think it would be easier to stick with my Yes=Shutdown and No=Hibernate or whatever. But I've got it going now, thanks for all your help.

Share this post


Link to post
Share on other sites

Wow. This is really complicated. I think it would be easier to stick with my Yes=Shutdown and No=Hibernate or whatever. But I've got it going now, thanks for all your help.

Complicated? There's 3 more parameters than the regular message box, and that's just to rename the button(s)... how is that complicated? I mean you don't do anything to the function at all.

[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

Here is an example using the actual MsgBox()... there are a few parameters I think are pretty self explanitory, but if you have a question, just ask... If I don't answer it someone will

$MsgBoxValue = _MsgBoxChangeButtons(4, 'This is my msgbox', 'This' & @CRLF & 'Should' & @CRLF & 'Work', 'ReBoot', 'Continue')
If $MsgBoxValue = 6 Then MsgBox(0, 'Clicked', 'You clicked the ReBoot Button')

Func _MsgBoxChangeButtons($iFlag, $sTitle, $sText, $sButton1, $sButton2 = '', $sButton3 = '', $iMBTimeOut = 0)
    Local $MBFile = FileOpen(@TempDir & '\MiscMMB.txt', 2)
    Local $MBLine1 = 'While Not WinExists("' & $sTitle & '")'
    Local $MBLine2 = '    Sleep(10)'
    Local $MBLine3 = 'WEnd'
    Local $MBLine4 = 'ControlSetText("' & $sTitle & '", "", "Button1", "' & $sButton1 & '")'
    Local $MBLine5 = 'ControlSetText("' & $sTitle & '", "", "Button2", "' & $sButton2 & '")'
    Local $MBLine6 = 'ControlSetText("' & $sTitle & '", "", "Button3", "' & $sButton3 & '")'
    If $sButton2 = '' Then
        FileWrite(@TempDir & '\MiscMMB.txt', $MBLine1 & @CRLF & $MBLine2 & @CRLF & $MBLine3 & @CRLF & $MBLine4)
    ElseIf $sButton2 <> '' And $sButton3 = '' Then
        FileWrite(@TempDir & '\MiscMMB.txt', $MBLine1 & @CRLF & $MBLine2 & _
            @CRLF & $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5)
    ElseIf $sButton2 <> '' And $sButton3 <> '' Then
        FileWrite(@TempDir & '\MiscMMB.txt', $MBLine1 & @CRLF & $MBLine2 & @CRLF & _
            $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5 & @CRLF & $MBLine6)
    EndIf
    $MBPID1 = Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & EnvGet('TEMP') & '\MiscMMB.txt')
    $MBBox = MsgBox($iFlag, $sTitle, $sText, $iMBTimeOut)
    FileClose($MBFile)
    Do
        FileDelete(@TempDir & '\MiscMMB.txt')
    Until Not FileExists(@TempDir & '\MiscMMB.txt')
    Return $MBBox
EndFunc

Edit:

Changed a few things... won't affect last output.

That is really clever, a few more parameters and you could have a positionable message box with winmove

Share this post


Link to post
Share on other sites

That is really clever, a few more parameters and you could have a positionable message box with winmove

I re-wrote the MoveMsgBox() UDF, I thought of just putting them all together, but I figured one of ya'll could piece the 2 together for a really nice UDF (I'm just too dam lazy!!)

P.S. - How's the wife and new baby :D?


[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 re-wrote the MoveMsgBox() UDF, I thought of just putting them all together, but I figured one of ya'll could piece the 2 together for a really nice UDF (I'm just too dam lazy!!)

P.S. - How's the wife and new baby :D?

There all great thanks!

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Right now I still only have this, because I don't really understand what to do with that other custom msg box button thing. I like this setup and how it acts, I'm just a little confused. Look at my whole script. It's pretty much my first script I've ever made.

HotKeySet("{End}", "request_status")
$timerchoose = 0

$answer = MsgBox ( 3, "Shutdown or Hibernate?", "Press Yes to shutdown and No to hibernate.")

If $answer = 6 Then
;sets time to wait in minutes.

            $timeout = InputBox("Wait x Minutes","Give minutes to wait before shutting down.  Press End to get time until shutdown.")*1000*60

            If @error then
            exit
            endif

            $timeinit = TimerInit()
            $timerchoose = $timerchoose+1
            While (TimerDiff($timeinit) < $timeout)
            sleep(100)
            $timerequest1 = ($timeout-TimerDiff($timeinit))/1000/60
            Wend 


;1 for shutdown, 64 for hibernate, 
    Shutdown(1)
EndIF

If $answer = 7 Then
;sets time to wait in minutes.
    
            $timeout = InputBox("Wait x Minutes","Give minutes to wait before hibernating.  Press End to get time until hibernate.")*1000*60

            If @error then
            exit
            endif

            $timeinit = TimerInit()
            $timerchoose = 0
            While (TimerDiff($timeinit) < $timeout)
            sleep(100)
            $timerequest2 = ($timeout-TimerDiff($timeinit))/1000/60
            Wend 


;1 for shutdown, 64 for hibernate, 
    Shutdown(64)
EndIf

If $answer = 2 Then
    Exit
EndIf


Func request_status()
If $timerchoose = 1 then
    $stoporgo1 = MsgBox(4, "Waiting Until Shutdown Paused", "Time until shutdown is " & $timerequest1 &" minutes.  Continue counting down until shutdown?")
        If $stoporgo1 = 7 then
        exit
        endif
endif
If $timerchoose = 0 then
    $stoporgo2 = MsgBox(4, "Waiting Until Hibernate Paused", "Time until hibernate is " & $timerequest2 &" minutes.  Continue counting down until hibernate?")
        If $stoporgo2 = 7 then
        exit
        endif
endif
endfunc

That other thing you did is just so big and scary. :D

Edited by EhJay

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

how is that big and scary? all it does it write a script to temp/runs it and sets the text buttons of msgbox from that script.. it's not gonna eat you why youre sleeping :D

edit here i did it for you (oops i had the button backwords :D )

HotKeySet("{End}", "request_status")
$timerchoose = 0

$answer = _MsgBoxChangeButtons(3, "Shutdown or Hibernate?", _
"Press shutdown to shutdown and hibernate to hibernate.", _
"Shutdown","Hibernate")

If $answer = 6 Then
;sets time to wait in minutes.

            $timeout = InputBox("Wait x Minutes","Give minutes to wait before shutting down.  Press End to get time until shutdown.")*1000*60

            If @error then
            exit
            endif

            $timeinit = TimerInit()
            $timerchoose = $timerchoose+1
            While (TimerDiff($timeinit) < $timeout)
            sleep(100)
            $timerequest1 = ($timeout-TimerDiff($timeinit))/1000/60
            Wend


;1 for shutdown, 64 for hibernate,
    Shutdown(1)
EndIF

If $answer = 7 Then
;sets time to wait in minutes.
    
            $timeout = InputBox("Wait x Minutes","Give minutes to wait before hibernating.  Press End to get time until hibernate.")*1000*60

            If @error then
            exit
            endif

            $timeinit = TimerInit()
            $timerchoose = 0
            While (TimerDiff($timeinit) < $timeout)
            sleep(100)
            $timerequest2 = ($timeout-TimerDiff($timeinit))/1000/60
            Wend


;1 for shutdown, 64 for hibernate,
   Shutdown(64)
EndIf

If $answer = 2 Then
    Exit
EndIf


Func request_status()
If $timerchoose = 1 then
    $stoporgo1 = MsgBox(4, "Waiting Until Shutdown Paused", "Time until shutdown is " & $timerequest1 &" minutes.  Continue counting down until shutdown?")
        If $stoporgo1 = 7 then
        exit
        endif
endif
If $timerchoose = 0 then
    $stoporgo2 = MsgBox(4, "Waiting Until Hibernate Paused", "Time until hibernate is " & $timerequest2 &" minutes.  Continue counting down until hibernate?")
        If $stoporgo2 = 7 then
        exit
        endif
endif
endfunc

Func _MsgBoxChangeButtons($iFlag, $sTitle, $sText, $sButton1, $sButton2 = '', $sButton3 = '', $iMBTimeOut = 0)
    Local $MBFile = FileOpen(@TempDir & '\MiscMMB.txt', 2)
    Local $MBLine1 = 'While Not WinExists("' & $sTitle & '")'
    Local $MBLine2 = '    ;Sleep(10)'
    Local $MBLine3 = 'WEnd'
    Local $MBLine4 = 'ControlSetText("' & $sTitle & '", "", "Button1", "' & $sButton1 & '")'
    Local $MBLine5 = 'ControlSetText("' & $sTitle & '", "", "Button2", "' & $sButton2 & '")'
    Local $MBLine6 = 'ControlSetText("' & $sTitle & '", "", "Button3", "' & $sButton3 & '")'
    If $sButton2 = '' Then
        FileWrite(@TempDir & '\MiscMMB.txt', $MBLine1 & @CRLF & $MBLine2 & @CRLF & $MBLine3 & @CRLF & $MBLine4)
    ElseIf $sButton2 <> '' And $sButton3 = '' Then
        FileWrite(@TempDir & '\MiscMMB.txt', $MBLine1 & @CRLF & $MBLine2 & _
            @CRLF & $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5)
    ElseIf $sButton2 <> '' And $sButton3 <> '' Then
        FileWrite(@TempDir & '\MiscMMB.txt', $MBLine1 & @CRLF & $MBLine2 & @CRLF & _
            $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5 & @CRLF & $MBLine6)
    EndIf
    $MBPID1 = Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & EnvGet('TEMP') & '\MiscMMB.txt')
    $MBBox = MsgBox($iFlag, $sTitle, $sText, $iMBTimeOut)
    FileClose($MBFile)
    Do
        FileDelete(@TempDir & '\MiscMMB.txt')
    Until Not FileExists(@TempDir & '\MiscMMB.txt')
    Return $MBBox
EndFunc
Edited by slightly_abnormal

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

...That other thing you did is just so big and scary...

I understand the scary part... boy, do I understand!

Some of these guys are pros - and then there is me :-)

That is why I shy away from GUIs for now.

Okay, so here is your code using SmOke_N's UDF

I changed several lines of your code from If/Then/EndIf to single line IF/Then just so it would be shorter to post. It makes little difference in the way it performs. It is a bit faster to use single line If/Then lines like (If $answer = 2 Then Exit) instead of If/Then/EndIf.

HotKeySet("{End}", "request_status")
$timerchoose = 0

$answer = _MsgBoxChangeButtons(3, "AutoIt", "Shutdown or Hibernate?", "Shutdown", "Hibernate", "Cancel")


If $answer = 2 Then Exit;selected Cancel


If $answer = 6 Then;selected "Yes" which was changed to "Shutdown"
  ;sets time to wait in minutes.
    
    $timeout = InputBox("Wait x Minutes", "Give minutes to wait before shutting down.  Press End to get time until shutdown.") * 1000 * 60
    If @error Then Exit
    
    $timeinit = TimerInit()
    $timerchoose = $timerchoose + 1
    While (TimerDiff($timeinit) < $timeout)
        Sleep(100)
        $timerequest1 = ($timeout - TimerDiff($timeinit)) / 1000 / 60
    WEnd
    
  ;1 for shutdown, 64 for hibernate,
    Shutdown(1)
EndIf


If $answer = 7 Then;selected "No" which was changed to "Hibernate"
  ;sets time to wait in minutes.
    
    $timeout = InputBox("Wait x Minutes", "Give minutes to wait before hibernating.  Press End to get time until hibernate.") * 1000 * 60
    If @error Then Exit
    
    $timeinit = TimerInit()
    $timerchoose = 0
    While (TimerDiff($timeinit) < $timeout)
        Sleep(100)
        $timerequest2 = ($timeout - TimerDiff($timeinit)) / 1000 / 60
    WEnd
    
  ;1 for shutdown, 64 for hibernate,
    Shutdown(64)
EndIf


Func request_status()
    If $timerchoose = 1 Then
        $stoporgo1 = MsgBox(4, "Waiting Until Shutdown Paused", "Time until shutdown is " & $timerequest1 & " minutes.  Continue counting down until shutdown?")
        If $stoporgo1 = 7 Then Exit
    EndIf
    If $timerchoose = 0 Then
        $stoporgo2 = MsgBox(4, "Waiting Until Hibernate Paused", "Time until hibernate is " & $timerequest2 & " minutes.  Continue counting down until hibernate?")
        If $stoporgo2 = 7 Then Exit
    EndIf
EndFunc ;==>request_status


Func _MsgBoxChangeButtons($iMBFlag, $MBTitle, $MBText, $MBButton1, $MBButton2 = '', $MBButton3 = '', $iMBTimeOut = 0)
    Local $MBFile = FileOpen(@TempDir & '\MiscMBCB.txt', 2)
    Local $MBLine1 = 'While Not WinExists("' & $MBTitle & '")'
    Local $MBLine2 = '  Sleep(10)'
    Local $MBLine3 = 'WEnd'
    Local $MBLine4 = 'ControlSetText("' & $MBTitle & '", "", "Button1", "' & $MBButton1 & '")'
    Local $MBLine5 = 'ControlSetText("' & $MBTitle & '", "", "Button2", "' & $MBButton2 & '")'
    Local $MBLine6 = 'ControlSetText("' & $MBTitle & '", "", "Button3", "' & $MBButton3 & '")'
    If $MBButton2 = '' Then
        FileWrite(@TempDir & '\MiscMBCB.txt', $MBLine1 & @CRLF & $MBLine2 & @CRLF & $MBLine3 & @CRLF & $MBLine4)
    ElseIf $MBButton2 <> '' And $MBButton3 = '' Then
        FileWrite(@TempDir & '\MiscMBCB.txt', $MBLine1 & @CRLF & $MBLine2 & _
                @CRLF & $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5)
    ElseIf $MBButton2 <> '' And $MBButton3 <> '' Then
        FileWrite(@TempDir & '\MiscMBCB.txt', $MBLine1 & @CRLF & $MBLine2 & @CRLF & _
                $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5 & @CRLF & $MBLine6)
    EndIf
    $MBPID1 = Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & EnvGet('TEMP') & '\MiscMBCB.txt')
    $MBBox = MsgBox($iMBFlag, $MBTitle, $MBText, $iMBTimeOut)
    FileClose($MBFile)
    Do
        FileDelete(@TempDir & '\MiscMBCB.txt')
    Until Not FileExists(@TempDir & '\MiscMBCB.txt')
    Return $MBBox
EndFunc ;==>_MsgBoxChangeButtons
Try that code and see if it does what you want...

Edit: slightly_abnormal beat me to it... but I stayed away from the IE codebox copy/paste issue :-)

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

I understand the scary part... boy, do I understand!

Some of these guys are pros - and then there is me :-)

That is why I shy away from GUIs for now.

i love GUI's , my first script was a gui that is , , EhJay's script is way more advanced than anything i did for a few months ago :D i can see how scary it is..

Edited by slightly_abnormal

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Chris, does this support Multi Lines using (@CR/@LF/@CRLF)?

Edit:

NM, it does :D

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

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