这篇文章简述MessageBox()的返回值,先看一段代码:
#include "stdafx.h"
#include "stdio.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
int result = MessageBox(NULL, TEXT("你吃了吗?"), TEXT("问题"), MB_YESNO | MB_ICONQUESTION);
char * resultStr = new char;
sprintf(resultStr, "%d", result); // 将int型数据转化为char*
MessageBox(NULL, resultStr, TEXT("结果"), MB_OK); // 弹出结果
return 0;
}
结果:单击“是(Yes)”为6,“否(No)”为7.
更改MessageBox()的第四个参数的按钮宏类型,可以得到不同类型按钮的返回值.