windows程序設計 MessageBox消息框

MessageBox函數windows

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就能看到和消息框的樣式了。3d

MessageBox函數還可返回IDYES、IDNO、IDCANCEL、IDABORT、 IDRETRY或IDIGNORE。code

相關文章
相關標籤/搜索