Message Box:
Message Box is a control in Visual C++. It is similar to alert box in JavaScript. This control is used to display any message on the window screen. Here is the syntax for a message box -
Syntax:
MessageBox (“Description”,
“Title string”, Button ID)
In description field we put the message.
Title string is displayed as title of message box.
Button ID decides which type of button is to displayed on the message box.
Ex:
MessageBox("Some Message!!!","Caption",MB_OK)
The above MessageBox code will display a output like this -
MessageBox function can be called within a visual C++ as a simple function or an event.
There are some Button Ids that can be passed to the MessageBox funtion. According to these button Ids different different buttons are displayed on the window.
Button_ID
|
Buttons
|
MB_OK
|
Ok
|
MB_OKCANCEL
|
Ok, Cancel
|
MB_YESNO
|
Yes, No
|
MB_YESNOCANCEL
|
Yes, No, Cancel
|
MB_RETRYCANCEL
|
Retry, Cancel
|
MB_ABORTRETRYIGNORE
|
Abort, Retry, Cancel
|
And the below table show the return value of a MessageBox function.
For example if user click Ok button on a Message Box then it will a "IDOK" as a return value.
Return
Value
|
Button
|
IDOK
|
Ok
|
IDCANCEL
|
Cancel
|
IDRETRY
|
Retry
|
IDYES
|
Yes
|
IDNO
|
No
|
IDABORT
|
Abort
|
IDIGNORE
|
Ignore
|
Code including MessageBox:
int result
= MessageBox (“Select one option”, “Title”, MB_YESNO);
switch(result)
{
case IDYES:
m_msg = “Yes Button clicked”;
break;
case IDNO:
m_msg = “No Button clicked”;
}
This is a simple MessageBox program which which will show a message box with two buttons Yes and No.
0 comments:
Post a Comment