Jump to content

Msgbox and cancel button


ant2ne
 Share

Recommended Posts

Read MsgBox() in the helpfile...

While MsgBox(4, "Shutting Down", "This computer will do something in a 10 seconds. Press NO to cancel", 10) <> 7
    Sleep(10)
WEnd
I don't think you understand my question. How do I determine if cancel or ok was pressed. Like,

if OK is pressed then X =0 
if CANCEL is pressed then X = 1
Link to comment
Share on other sites

$return_value = MsgBox(4,"Shutting Down", "This computer will do something in a 10 seconds. Press NO to cancel",10)
Switch $return_value
    case 1 ;OK ---> Flags: 0, 1
        MsgBox(0, "Return Value", "OK")
    case 2 ;cancel ---> Flags: 1, 3, 5, 6
        MsgBox(0, "Return Value", "Cancel")
    case 3 ;abort ---> Flags: 2
        MsgBox(0, "Return Value", "Abort")
    case 4 ;retry ---> Flags: 2, 5
        MsgBox(0, "Return Value", "Retry")
    case 5 ;Ignore ---> Flags: 2
        MsgBox(0, "Return Value", "Ignore")
    case 6 ;Yes ---> Flags: 3, 4
        MsgBox(0, "Return Value", "Yes")
    case 7 ;No ---> Flags: 3, 4
        MsgBox(0, "Return Value", "No")
    case 10 ;Try Again ---> Flags: 6
        MsgBox(0, "Return Value", "Try again")
    case 11 ;Continue ---> Flags: 6
        MsgBox(0, "Return Value", "Continue")
EndSwitch

Link to comment
Share on other sites

First... RTFM... you invoke the msgbox with flag=4, meaning 'Yes and No' and no 'OK and Cancel', which would be flag=1... then as you can see in my code, the loop ends when the msgbox() returns 7, which means 'No'.

Link to comment
Share on other sites

First... RTFM... you invoke the msgbox with flag=4, meaning 'Yes and No' and no 'OK and Cancel', which would be flag=1... then as you can see in my code, the loop ends when the msgbox() returns 7, which means 'No'.

Cancel or OK the example would have been enough. The manual I got doesn't say anything about "<> 7" or "while" and "wend". I highlight the word msgbox and press F1 to view the help file. If you have a better manual, please let me know where I can get it. I don't want it to loop waiting for a reply. I never said I wanted it to loop waiting for a reply. I nfact when the ,10) second limit of the msgbox statment is reached, I want the code to continue. Otherwise I wouldn't have put it in there. What I'm looking for is something more like what sandin posted. But that wasn't in my help file either. If I knew WHAT I was looking for, I could have found it. I always feel that the purpose of these forums is to learn about the things that you didn't even know you didn't know.

select word MsgBox and press F1. I can see where it says "Button Pressed Return Value" but it doesn't say how to use those. Please forgive my ignorance as I try to learn.

MsgBox

--------------------------------------------------------------------------------

Displays a simple message box with optional timeout.

MsgBox ( flag, "title", "text" [, timeout [, hwnd]] )

Parameters

flag The flag indicates the type of message box and the possible button combinations. See remarks.

title The title of the message box.

text The text of the message box.

timeout [optional] Timeout in seconds. After the timeout has elapsed the message box will be automatically closed. The default is 0, which is no timeout.

hwnd [optional] The window handle to use as the parent for this dialog.

Return Value

Success: Returns the ID of the button pressed.

Failure: Returns -1 if the message box timed out.

Button Pressed Return Value

OK 1

CANCEL 2

ABORT 3

RETRY 4

IGNORE 5

YES 6

NO 7

TRY AGAIN ** 10

CONTINUE ** 11

Remarks

The flag parameter can be a combination of the following values:

decimal flag Button-related Result hexadecimal flag

0 OK button 0x0

1 OK and Cancel 0x1

2 Abort, Retry, and Ignore 0x2

3 Yes, No, and Cancel 0x3

4 Yes and No 0x4

5 Retry and Cancel 0x5

6 ** Cancel, Try Again, Continue 0x6

decimal flag Icon-related Result hexadecimal flag

0 (No icon) 0x0

16 Stop-sign icon 0x10

32 Question-mark icon 0x20

48 Exclamation-point icon 0x30

64 Information-sign icon consisting of an 'i' in a circle 0x40

decimal flag Default-related Result hexadecimal flag

0 First button is default button 0x0

256 Second button is default button 0x100

512 Third button is default button 0x200

decimal flag Modality-related Result hexadecimal flag

0 Application 0x0

4096 System modal (dialog has an icon) 0x1000

8192 Task modal 0x2000

decimal flag Miscellaneous-related Result hexadecimal flag

0 (nothing else special) 0x0

262144 MsgBox has top-most attribute set 0x40000

524288 title and text are right-justified 0x80000

** Only valid on Windows 2000/XP and above.

For example, to specify a SYSTEMMODAL box with the YES/NO buttons the flag value would be 4096+4 (or 4100) If using hexadecimal flags, that would be 0x1000+0x4 (or 0x1004).

A message box appears centered on screen and resizes according to the text it contains. However, the title could get truncated if the SYSTEMMODAL flag (4096) is used..

If "title" is equal to Default keyword @Scriptname is used

Related

InputBox, ToolTip, TrayTip, SplashTextOn

Example

MsgBox(4096, "Test", "This box will time out in 10 seconds", 10)

Link to comment
Share on other sites

akn, sorry for my rudeness :) ...

if you want it this way, try:

if MsgBox(266513,"Shutting Down", "This computer will shut down in a 10 seconds...." & @crlf & @crlf & "Press CANCEL to abort the shutdown.",10) = 2 Then
    ; do not Shutdown
    MsgBox(0,'','Cancel pressed')
Else
    ; Shutdown
    MsgBox(0,'','Ok pressed or msgbox timed out...')
EndIf
Edited by KaFu
Link to comment
Share on other sites

  • Moderators

ant2ne,

Set a variable to the return value of the message box. Then you can use the variable as you wish (I have used a Switch...Case in this example):

$answer = MsgBox(32 + 4, "Query", "Are you sure?")

Switch $answer
    Case 6; Yes
        ExitLoop
    Case 7; No
        Return
EndSwitch

The possible value of the variable depends on the buttons you have chosen to use in the initial parameter of the MsgBox function.

M23

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

ant2ne,

Set a variable to the return value of the message box. Then you can use the variable as you wish (I have used a Switch...Case in this example):

$answer = MsgBox(32 + 4, "Query", "Are you sure?")

Switch $answer
    Case 6; Yes
        ExitLoop
    Case 7; No
        Return
EndSwitch

The possible value of the variable depends on the buttons you have chosen to use in the initial parameter of the MsgBox function.

M23

I see that in sadin's reply. I never knew that was how one captures return values. But now I do. Very interesting and I plan to use it a lot in the future.

THANKS

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...