#include <windows.h> // windows程序必须包含的头文件
#include <stdlib.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);//窗口函数说明
//----------------------以下初始化窗口类---------------------
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow) // 程序切入点
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="窗口";
char lpszTitle[]="My_Windows";
//初始化窗口的属性
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(WHITE_BRUSH);
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);
//显示窗口
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)
{
// 这里可以加好多消息,这个例程什么也没有实现所以只有一个消息分支WM_DESTROY
case WM_DESTROY:
PostQuitMessage(0);
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return (0);
}