MessageBox函数,想必很多人都不会陌生!别看这个函数很简单,但是有一些功能,有人未必用过:P
请看下面的实例:
这个实例有什么特别的地方吗?自己编译运行一下就知道啦!
既然,提及到了这个函数,那就干脆写得完整一点吧!
1、MessageBox函数原型
它有4个参数,上面注释已经说明了各个参数的意义。下面,具体引述第4个参数的用法。
2、参数UINT uType
To indicate the buttons displayed in the message box, specify one of the following values.
Value | Meaning |
MB_ABORTRETRYIGNORE | The message box contains three push buttons: Abort, Retry, and Ignore. |
MB_CANCELTRYCONTINUE | Windows 2000/XP: The message box contains three push buttons: Cancel, Try Again, Continue. Use this message box type instead of MB_ABORTRETRYIGNORE. |
MB_HELP | Windows 95/98/Me, Windows NT 4.0 and later: Adds a Help button to the message box. When the user clicks the Help button or presses F1, the system sends a WM_HELP message to the owner. |
MB_OK | The message box contains one push button: OK. This is the default. |
MB_OKCANCEL | The message box contains two push buttons: OK and Cancel. |
MB_RETRYCANCEL | The message box contains two push buttons: Retry and Cancel. |
MB_YESNO | The message box contains two push buttons: Yes and No. |
MB_YESNOCANCEL | The message box contains three push buttons: Yes, No, and Cancel. |
To display an icon in the message box, specify one of the following values.
Value | Meaning |
MB_ICONEXCLAMATION, | An exclamation-point icon appears in the message box. |
MB_ICONINFORMATION, MB_ICONASTERISK | An icon consisting of a lowercase letter i in a circle appears in the message box. |
MB_ICONQUESTION | A question-mark icon appears in the message box. |
MB_ICONSTOP, | A stop-sign icon appears in the message box. |
Value | Meaning |
MB_DEFBUTTON1 | The first button is the default button. MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified. |
MB_DEFBUTTON2 | The second button is the default button. |
MB_DEFBUTTON3 | The third button is the default button. |
MB_DEFBUTTON4 | The fourth button is the default button. |
3、函数返回值
If the function succeeds, the return value is one of the following menu-item values.
Value | Meaning |
IDABORT | Abort button was selected. |
IDCANCEL | Cancel button was selected. |
IDCONTINUE | Continue button was selected. |
IDIGNORE | Ignore button was selected. |
IDNO | No button was selected. |
IDOK | OK button was selected. |
IDRETRY | Retry button was selected. |
IDTRYAGAIN | Try Again button was selected. |
IDYES | Yes button was selected. |
后记:一些常用的东西反而容易忘记!为了避免每次都得查MSDN,故整理如此,供日后参考。偷懒了,直接贴MSDN的资料上来:P