First Win32 App, 第一个Win32 GUI程序

#include <windows.h>



LONG WINAPI WndProc(HWND, UINT,WPARAM,LPARAM);	//回调原型



int WINAPI WinMain(      

				   HINSTANCE 

				   hInstance,

				   HINSTANCE 

				   hPrevInstance,

				   LPSTR 

				   lpCmdLine,

				   int 

				   nCmdShow

				   )

{



	WNDCLASS wc;

	HWND hwnd;

	MSG msg;



	//1.设计窗体

	wc.style = 0;

	wc.lpfnWndProc = (WNDPROC)WndProc;

	wc.cbClsExtra = 0;

	wc.cbWndExtra = 0;

	wc.hInstance = hInstance;

	wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);

	wc.hCursor = LoadCursor(NULL,IDC_ARROW);

	//wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);

	wc.hbrBackground = (HBRUSH)(COLOR_GRAYTEXT);

	

	wc.lpszMenuName = NULL;

	wc.lpszClassName = "MyWndClass";



	RegisterClass(&wc);		//2.注册窗体



	hwnd = CreateWindow(	//3.创建窗体

			"MyWndClass",			//WNDCLASS NAME

			"SDK APPLICATION标题",		//WINDOW TITLE

			WS_OVERLAPPEDWINDOW,	//WINDOW STYLE

			CW_USEDEFAULT,			//Horizontal position

			CW_USEDEFAULT,			//Vertical position

			CW_USEDEFAULT,			//Initial width

			CW_USEDEFAULT,			//Initial height

			HWND_DESKTOP,			//Handle of parent window

			NULL,					//Menu handle

			hInstance,				//Application's instance handle

			NULL					//Window-creation data

		);





	ShowWindow(hwnd,nCmdShow);	//4.显示更新窗体

	UpdateWindow(hwnd);



	while(GetMessage(&msg,NULL,0,0)){		//5.消息循环

		TranslateMessage(&msg);

		DispatchMessage(&msg);

	}

	return msg.wParam;

}





LRESULT CALLBACK WndProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam){

	

	PAINTSTRUCT ps;

	HDC hdc;

	switch(message){

	case WM_PAINT:

		hdc=BeginPaint(hwnd,&ps);

		Ellipse(hdc,0,0,200,100);

		EndPaint(hwnd,&ps);

		return 0;

		

	case WM_DESTROY:

		PostQuitMessage(0);

		return 0;

	}

	return DefWindowProc(hwnd,message,wParam,lParam);

}

 

你可能感兴趣的:(first)