#include <windows.h>
#include <stdio.h>//c语言的头文件
//所定义的函数原型声明
LRESULT CALLBACK WindowProc(
HWND chuangkou,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
//查看msdn
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
//开始设定窗口类
{
WNDCLASS cls;//设计窗口类
cls.cbClsExtra=0;//类的额外附加字节数
cls.cbWndExtra=0;//窗口额外附加字节数,不需要
cls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);//强制转换
cls.hCursor=LoadCursor(NULL,IDC_CROSS);//应用程序事例号,光标标识符
cls.hIcon=LoadIcon(NULL,IDI_HAND);//图标标识,也采用标准的
cls.hInstance=hInstance;
cls.lpfnWndProc=WindowProc;//窗口过程函数
cls.lpszClassName=”xdf”;//类名
cls.lpszMenuName=NULL;//暂时不需要设定菜单
cls.style=CS_HREDRAW | CS_VREDRAW;//类的类型,水平,垂直重画
RegisterClass(&cls);//注册窗口类
HWND chuangkou;//创建窗口
chuangkou=CreateWindow(“xdf”,”xdfxdf”,WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);//查看msdnHWND
/*
CreateWindow(
LPCTSTR lpClassName,//类名
LPCTSTR lpWindowName,//窗口名字
DWORD dwStyle,//窗口类型
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,//父窗口
HMENU hMenu,//菜单
HINSTANCE hInstance,//实例
LPVOID lpParam//窗口创建的数据
);
*/
ShowWindow(chuangkou,SW_SHOWNORMAL);//显示窗口
UpdateWindow(chuangkou);//更新窗口
MSG xiaoxi;//windows下编写程序都是要基于消息的机制
while (GetMessage(&xiaoxi,NULL,0,0))//获取所有窗口消息
{
TranslateMessage(&xiaoxi);//转化消息
DispatchMessage(&xiaoxi);
}
return 0;
}
//接下来写窗口过程函数代码
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_CHAR:
char dychar[20];
sprintf(dychar,”d%”,wParam);
MessageBox(hwnd,dychar,”xdf”,0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,”xdf,clicked”,”xdfxdf”,0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,”xdfxdf”,strlen(“123123″));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,”xdfxdf”,strlen(“123123″));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}