
MessageBox函数
int
WINAPI
MessageBoxW(
HWND hWnd,//窗口句柄
LPCWSTR lpText,//消息框主体显示的字符串
LPCWSTR lpCaption,//消息框标题上的字符串
UINT uType//样式
);
样式有
#define MB_OK 0x00000000L
#define MB_OKCANCEL 0x00000001L
#define MB_ABORTRETRYIGNORE 0x00000002L
#define MB_YESNOCANCEL 0x00000003L
#define MB_YESNO 0x00000004L
#define MB_RETRYCANCEL 0x00000005L
测试代码
#include <windows.h> //hInstance:执行实体句柄,lpCmdLine:执行程序的命令列,nCmdShow:程序最初显示的方式。
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ //窗口句柄,消息框主体显示的字符串,消息框标题上的字符串,样式。
MessageBox(NULL, TEXT("Hello, small insect !"), TEXT("message"), MB_OK);
MessageBox(NULL, TEXT("Hello, small insect !"), TEXT("message"), MB_OKCANCEL);
MessageBox(NULL, TEXT("Hello, small insect !"), TEXT("message"), MB_ABORTRETRYIGNORE);
MessageBox(NULL, TEXT("Hello, small insect !"), TEXT("message"), MB_YESNOCANCEL);
MessageBox(NULL, TEXT("Hello, small insect !"), TEXT("message"), MB_YESNO);
MessageBox(NULL, TEXT("Hello, small insect !"), TEXT("message"), MB_RETRYCANCEL); return 0;
}
运行之后的结果是
除了这些样式,还有别的样式,可以选中MB_OK,按F12就能看到和消息框的样式了。
MessageBox函数还可返回IDYES、IDNO、IDCANCEL、IDABORT、 IDRETRY或IDIGNORE。