c++——chap01

#include <windows.h>

LRESULT CALLBACK WindowProc(HWND hwnd,
							UINT uMsg,
							WPARAM wParam,
							LPARAM lParam)
{
	switch(uMsg)
	{
	case WM_CHAR:
		break;
	
	case WM_LBUTTONDOWN:
		MessageBox(hwnd,"left mouse clicked","messagebox标题",MB_OK);
		break;

	case WM_CLOSE:
		if(IDYES == MessageBox(hwnd,"是否真的结束?","lwg2011",MB_YESNO))
		{
			DestroyWindow(hwnd);
		}
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd,uMsg,wParam,lParam);
	}
	
	return 0;
}


int CALLBACK WinMain(HINSTANCE hInstance,
					 HINSTANCE hPrevInstance,
					 LPSTR lpCmdLine,
					 int nShowCmd)
{
	// 设计一个窗口类
	WNDCLASS wndclass;
	wndclass.style = CS_VREDRAW | CS_HREDRAW; 
	wndclass.lpfnWndProc = WindowProc;
	wndclass.cbClsExtra = 0;
	wndclass.cbWndExtra = 0;
	wndclass.hInstance = hInstance;
	wndclass.hIcon = LoadIcon(NULL, IDI_ASTERISK);
	wndclass.hCursor = LoadCursor(NULL,IDC_HELP);
	wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName = NULL;
	wndclass.lpszClassName = "lwg2011";

	// 注册一个窗口类
	RegisterClass(&wndclass);

	// 创建一个窗口
	HWND hwnd;
	hwnd = CreateWindow("lwg2011","我的第一个窗口",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);
	
	// 显示一个窗口
	ShowWindow(hwnd,SW_SHOWNORMAL);
	UpdateWindow(hwnd);


	// 消息循环
	MSG msg;
	while(GetMessage(&msg,NULL,0,0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}



	return 0;
}

 

你可能感兴趣的:(C++,null,callback,include)