#include <windows.h>
LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain1(HINSTANCE hInst, HINSTANCE, LPSTR szCmd, int nShow)
{
WNDCLASS wndClass;
TCHAR *ClassName = TEXT("MyClass");
HWND hwnd;//用来记录窗口句柄
MSG msg; //定义一个消息结构,用来存储获取的消息
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClass.lpfnWndProc = wndProc;
wndClass.lpszClassName = ClassName; //类名
wndClass.lpszMenuName = NULL; //暂时不要菜单
wndClass.style = CS_VREDRAW | CS_HREDRAW;
RegisterClass(&wndClass);//注册窗口
//#define CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y,\nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
hwnd = CreateWindow(
ClassName/*窗口类*/,
TEXT("Hello"/*窗口名*/),
WS_OVERLAPPEDWINDOW/*窗口类型*/,
CW_USEDEFAULT/*默认窗口位置 横坐标*/,
CW_USEDEFAULT/*默认窗口位置 纵坐标*/,
500/*窗口的宽*/,
300/*窗口的高*/,
NULL/*父窗口:没有父窗口,默认是桌面*/,
NULL/*没有菜单*/,
hInst/*程序实例句柄*/,
NULL );
ShowWindow(hwnd, nShow);//显示窗口
UpdateWindow(hwnd);//刷新窗口
while (GetMessage(&msg, NULL, 0, 0))//如果给窗口发送消息0 ,就退出循环结束程序
{
TranslateMessage(&msg);//翻译
DispatchMessage(&msg);//把消息发送给处理消息的窗口程序
}
return 0;
}
LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lparam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);//给程序发送一条退出消息 退出值0
return 0;
default:
return DefWindowProc(hwnd, message, wParam, lparam);//自己不处理,交给系统处理
}
}