第一个Win32窗口程序,纪念自己的Windows编程之旅

#include "windows.h"
LRESULT WndProc(HWND hWnd,UINT nMsg,WPARAM wParam,LPARAM lParam)
{
   return DefWindowProc(hWnd,nMsg,wParam,lParam);
}
int WinMain(HINSTANCE hInstance,
	    HINSTANCE hPreInstance,LPSTR lpCmdLine,
		int nCmdShow)
{
   WNDCLASS wc = {0};
   HWND hWnd = 0;
   MSG nMsg = {0};
   wc.style = CS_HREDRAW|CS_VREDRAW;
   wc.lpfnWndProc = (WNDPROC)WndProc;
   wc.cbClsExtra = 0;
   wc.cbWndExtra = 0;
   wc.hInstance = hInstance;
   wc.hIcon = NULL;
   wc.hCursor = NULL;
   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
   wc.lpszMenuName = NULL;
   wc.lpszClassName = "Main"; 
   RegisterClass(&wc);//将以上填写的信息全部注册到操作系统中
   hWnd = CreateWindow("Main","Window",
		WS_OVERLAPPEDWINDOW,100,100,500,500,NULL,NULL,hInstance,NULL);//在内存中出现关于窗口的各项数据
   ShowWindow(hWnd,SW_SHOW);
   while(GetMessage(&nMsg,NULL,0,0))
   {
	TranslateMessage(&nMsg);
	DispatchMessage(&nMsg);//将消息派发给自己定义的函数
   }
   return 0;
}
开始自己的Window编程之旅,希望有个良好的开端,对自己也很有信心。加油!!

你可能感兴趣的:(C/C++,印记)