第一、创建一个窗口的Win32程序的7个步骤:
1、编写WinMain函数,可以在MSDN上查找和复制;
2、设计窗口类WNDCLASS;
3、注册窗口类;
4、创建窗口类;
5、显示并更新窗口;
6、编写消息循环;
7、编写窗口过程函数;窗口过程函数的语法,可以通过MSDN查看WNDCLASS的lpfnWndProc成员变量,在这个成员的解释中可以查到。
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
//1、编写WinMain函数
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
//2、设计窗口类
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="sunxin2006";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
//3、注册窗口类
RegisterClass(&wndcls);
//4、创建窗口
HWND hwnd;
hwnd=CreateWindow("sunxin2006","http://www.sunxin.org",WS_OVERLAPPEDWINDOW,
0,0,600,400,NULL,NULL,hInstance,NULL);
//5、显示及更新窗口