第一个win32窗口程序

1、打开vc6.0,文件->新建一个win32 Application工程

2、新建一个c++源文件,内容如下:

#include <stdio.h>
#include <windows.h>
LRESULT CALLBACK CallWinMainProc(//回调函数声明
								 HWND hWnd,
								 UINT Msg,
								 WPARAM wParam,
								 LPARAM lParam
								 );
//主函数
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	TCHAR proName[] = TEXT("winmain");
	
	WNDCLASS wndclass;
	wndclass.style = CS_HREDRAW | CS_VREDRAW;//水平垂直大小改变是发出wm_print消息
	wndclass.hInstance = hInstance;
	wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);//左上角的图标,默认空白
	wndclass.cbClsExtra = 0;
	wndclass.cbWndExtra = 0;
	wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);//背景颜色,获取白色笔刷
	wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);//设置鼠标样式
	wndclass.lpszClassName = proName;//类名字
	wndclass.lpszMenuName = NULL;//菜单
	wndclass.lpfnWndProc = CallWinMainProc;//回调函数
	
	RegisterClass(&wndclass);//注册一个窗口类
	
	HWND hwnd;
	hwnd = CreateWindow(proName,"第一个窗口程序",WS_OVERLAPPEDWINDOW,0,0,400,400,NULL,NULL,hInstance,NULL);//创建窗口
	
	ShowWindow(hwnd,nCmdShow);//显示窗口
	UpdateWindow(hwnd);//刷新窗口
	
	MSG msg;
	while (GetMessageA(&msg,NULL,0,0)) {//循环获取消息队列里的消息
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	
	return 0;
}
//回调函数
LRESULT CALLBACK CallWinMainProc(
								 HWND hWnd,
								 UINT Msg,
								 WPARAM wParam,
								 LPARAM lParam
								 )
{
	switch(Msg) {
	case WM_CREATE:
		{
		}
		break;
	case WM_PAINT:
		
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd,Msg,wParam,lParam);
	}
	return 0;
}

3、程序运行效果图

image

posted @ 2012-12-29 16:58  浪浪仔  阅读(776)  评论(0编辑  收藏  举报