初识windows编程

helloworld程序

#include  
  
int WINAPI WinMain(  
        HINSTANCE hInstance,  
        HINSTANCE hPrevInstance,   
        PSTR szCmdLine, int iCmdShow )  
{  
    MessageBox( NULL, TEXT("Hello,world!"), TEXT("显示"), 0 );//0和MB_OK功能一样,都是出现一个确定按钮  
  
    return 0;  
}



编写windows程序要包含在windows.h头文件中


MessageBow()函数  用于对话框的创建显示和操作

原型 :int WINAPI MessageBox( HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType );

hWnd : 此参数若为NULL,则消息框没有父窗口,比如helloworld程序只有一个窗口

lpText: 消息框的内容

lpCaption: 消息框的标题

uType: 按钮设置

MB_OK
默认值。有一个确认按钮在里面。
MB_YESNO
有是和否在里面。
MB_ABORTRETRYIGNORE
有Abort(放弃),Retry(重试)和Ignore(跳过)
MB_YESNOCANCEL
消息框含有三个按钮:Yes,No和Cancel
MB_RETRYCANCEL
有Retry(重试)和Cancel(取消)
MB_OKCANCEL
消息框含有两个按钮:OK和Cancel

MessageBox返回值

返回值 含义
IDOK 用户按下了“确认”按钮
IDCANCEL 用户按下了“取消”按钮
IDABORT 用户按下了“中止”按钮
IDRETRY 用户按下了“重试”按钮
IDIGNORE 用户按下了“忽略”按钮
IDYES 用户按下了“是”按钮
IDNO 用户按下了“否”按钮

#define IDOK 1  确定 1

 #define IDCANCEL 2 取消 2

  #define IDABORT 3 放弃 3

  #define IDRETRY 4  重试 4

 #define IDIGNORE 5 忽略 5

  #define IDYES 6   是 6

#define IDNO 7   否 7


返回案例

#include
int WINAPI WinMain(
				   HINSTANCE hInstance,
				   HINSTANCE hPrevInstance,
				   PSTR szCmdLine, int iCmdShow)
{
	int s = MessageBox(NULL,TEXT("hello world"),TEXT("我是对话框"),MB_OKCANCEL);
	if (s==IDOK)//返回确定
	{
		MessageBox(NULL,TEXT("按下了“确定”按钮"),TEXT("提示"),0);
	}
	if (s==IDCANCEL)//返回取消
	{
		MessageBox(NULL,TEXT("按下了“取消”按钮"),TEXT("提示"),0);
	}
	return 0;
}



你可能感兴趣的:(初识windows编程)