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;
}

  

windows程序设计 MessageBox消息框

运行之后的结果是

windows程序设计 MessageBox消息框windows程序设计 MessageBox消息框windows程序设计 MessageBox消息框windows程序设计 MessageBox消息框windows程序设计 MessageBox消息框windows程序设计 MessageBox消息框

除了这些样式,还有别的样式,可以选中MB_OK,按F12就能看到和消息框的样式了。

MessageBox函数还可返回IDYES、IDNO、IDCANCEL、IDABORT、 IDRETRY或IDIGNORE。

 

相关文章:

  • 2021-05-20
  • 2022-12-23
  • 2021-11-02
  • 2021-09-18
  • 2022-12-23
  • 2021-07-17
  • 2021-12-14
  • 2022-12-23
猜你喜欢
  • 2021-08-28
  • 2021-10-17
  • 2022-12-23
  • 2021-11-17
  • 2021-10-28
  • 2021-10-31
  • 2021-09-06
相关资源
相似解决方案