#include
#include
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASS wc;
wc.style = CS_VREDRAW|CS_HREDRAW ;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hInstance = hInstance;
wc.lpszClassName = "mainwindow";
wc.lpszMenuName = NULL;
if(!RegisterClass(&wc))
{
MessageBeep(0);
return FALSE;
}
HWND hwnd;
hwnd = CreateWindow(
"mainwindow",
NULL,
WS_OVERLAPPED /*WS_POPUP | WS_VISIBLE*/,
0,0,500,400,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
MSG uMsg;
while(GetMessage(&uMsg,hwnd,0,0))
{
TranslateMessage(&uMsg);
DispatchMessage(&uMsg);
}
return uMsg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
//case WM_PAINT:
// break;
//case WM_KEYDOWN:
// break;
case WM_DESTROY:
DestroyWindow(hwnd);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
#include
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);//窗口消息处理函数
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow){
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="test";//窗口类名,实际没有意义
char lpszTitle[]="我的程序";//应用程序的窗口名
//LPCTSTR lpszClassName = TEXT("MyApp");
//LPCTSTR lpszTitle = TEXT("My Application");
hi=hInstance;//应用程序实例句柄可以在全局使用
///
//窗口类型设置/
///
wndclass.style=0;//窗口类型
wndclass.lpfnWndProc=WndProc;//窗口处理函数
wndclass.cbClsExtra=0;//窗口类扩展
wndclass.cbWndExtra=0;//窗口实例扩展
wndclass.hInstance=hInstance;//当前实例句柄
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);//最小化图标
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);//光标
wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);//背景
//wndclass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName=NULL;//菜单
wndclass.lpszClassName=lpszClassName;//窗口类名
///
///窗口类注册//
///
if(!RegisterClass(&wndclass)) {
MessageBeep(0);
return FALSE;
}
///
///创建窗口返回句柄
///
hwnd=CreateWindow(
lpszClassName,//窗口类名
lpszTitle,//标题名
WS_OVERLAPPEDWINDOW,//窗口风格
CW_USEDEFAULT,//左上角坐标
CW_USEDEFAULT,
CW_USEDEFAULT,//高和宽的大小
CW_USEDEFAULT,
NULL,
NULL,
hInstance,//创建窗口的应用程序句柄
NULL
);
hw=hwnd;//可以在全局使用
///
//显示窗口,进入消息循环///
///
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)//窗口消息处理函数
{ switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return (0);
}
其中括号中参数表示的意思如下: