#include <windows.h>
#include <commctrl.h>>
UINT IDC_BUTTON_1=200;
/* This is where all the input to the window goes to这是窗口的所有输入的位置 */
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {

	switch(Message) {
		//在创建窗口过程时 未显示窗口前 接收 WM_CREATE 这时可以创建控件 
		case WM_CREATE: {
			UINT IDC_BUTTON_1=200;
			HWND hButtonWnd=CreateWindow(WC_BUTTON,"确定",WS_CHILD|BS_PUSHBUTTON|WS_VISIBLE,100,100,50,20,hwnd,(HMENU)IDC_BUTTON_1,NULL,NULL);

		}
		break;
		//接收 来自button的点击事件 WM_COMMAND
		case WM_COMMAND: {
			UINT buttio_id=LOWORD(wParam);
			UINT nCode=HIWORD(wParam);
			if(nCode==BN_CLICKED && buttio_id==IDC_BUTTON_1) {
				MessageBox(hwnd,"弹出消息了","tip",MB_OK);
			}
		}
		break;
		/* Upon destruction, tell the main thread to stop 销毁时，告诉主线程停止*/
		case WM_DESTROY: {
			PostQuitMessage(0);
			break;
		}

		/* All other messages (a lot of them) are processed using default procedures */
		default:
			return DefWindowProc(hwnd, Message, wParam, lParam);
	}
	return 0;
}

/* The 'main' function of Win32 GUI programs: this is where execution starts */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	WNDCLASSEX wc; /* A properties struct of our window  窗口的一个属性结构体*/
	HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window 一个'HANDLE'，也就是H，或者一个指向窗口的指针*/
	MSG msg; /* A temporary location for all messages 所有消息的临时位置*/

	/* zero out the struct and set the stuff we want to modify 将结构归零并设置我们想要修改的内容 */
	memset(&wc,0,sizeof(wc));
	wc.cbSize		 = sizeof(WNDCLASSEX);
	wc.lpfnWndProc	 = WndProc; /* This is where we will send messages to 这是我们要发送消息的地方*/
	wc.hInstance	 = hInstance;
	wc.hCursor		 = LoadCursor(NULL, IDC_ARROW);

	/* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it 白色，COLOR_WINDOW只是一个系统颜色的#定义，尝试Ctrl+点击它*/
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	wc.lpszClassName = "WindowClass";
	wc.hIcon		 = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon 加载一个标准图标*/
	wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon 使用名称“A”来使用项目图标*/
	//MessageBox(NULL,"111111","标题",MB_ICONEXCLAMATION|MB_OK);
	if(!RegisterClassEx(&wc)) {
		MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
		return 0;
	}

	hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Caption123",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
	                      CW_USEDEFAULT, /* x */
	                      CW_USEDEFAULT, /* y */
	                      640, /* width */
	                      480, /* height */
	                      NULL,NULL,hInstance,NULL);

	if(hwnd == NULL) {
		MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
		return 0;
	}




	/*
		This is the heart of our program where all input is processed and
		sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
		this loop will not produce unreasonably high CPU usage
	*/
	while(GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */
		TranslateMessage(&msg); /* Translate key codes to chars if present */
		DispatchMessage(&msg); /* Send it to WndProc */
	}
	return msg.wParam;
}