Effect demo:
Run the program and pop up the following window:
Select: Yes
Select : No
Select again: No , this box will always pop up;
Select: Yes
Function introduction and usage:
MessageBox refers to displaying a modal dialog box that contains a system icon, a set of buttons, and a brief application-specific message, such as status or error information. An integer value is returned in the message box indicating which button the user clicked.
Function:
MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
Parameters:
hWnd:
This parameter represents the window owned by the message box. If NULL, the message box has no owning window.
lpText:
the content in the prompt box.
lpCaption:
The title of the prompt box.
uType:
Buttons and icons in the message box.
uType parameter:
parameter | The button that appears |
---|---|
MB_OK | confirm |
MB_YESNO | YES (yes), NO (no) |
MB_ABORTRETRYIGNORE | Abort (abandon), Retry (retry), Ignore (skip) |
MB_YESNOCANCEL | Yes、No、Cancel |
MB_RETRYCANCEL | Retry (retry), Cancel (cancel) |
MB_OKCANCEL | OK、Cancel |
return value
return value | select button |
---|---|
IDOK | OK |
IDCANCEL | CANCEL |
SIDE AWAY | ABORT |
IDRETRY | ETRY |
I know it | IGNORE |
IDYES | YES |
ID NO | NO |
Program source code:
#include <tchar.h>
#include <Windows.h>
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPTSTR lpCmdLine, INT nShowCmd)
{
UINT nRet = MessageBox(NULL, _T("我喜欢你!"), _T("告诉你一个秘密:"), MB_YESNO);
if (nRet == IDYES)
{
MessageBox(NULL, _T("爱你么么哒!"),_T(""), MB_OK);
}
if (nRet == IDNO)
{
while (1)
{
UINT mRet = MessageBox(NULL, _T("真的喜欢你"), _T("再选择一次嘛:"), MB_YESNO);
if (mRet == IDYES)
{
MessageBox(NULL, _T("我就知道你是爱我的"), _T(" "), MB_OK);
break;
}
}
}
return 0;
}