win基本流程
#include "resource.h"
#include <windows.h>
#define szWindowClass "ZS window"
HWND hwnd;
#include <windows.h>
#define szWindowClass "ZS window"
HWND hwnd;
//回调函数地址
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
//参数:窗口句柄,消息,消息参数,消息参数
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_KEYDOWN:
break;
case WM_COMMAND:
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR ipCmdLine, int nCmdShow)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX); //窗口的大小
wcex.style = CS_HREDRAW | CS_VREDRAW;//窗口的风格
wcex.lpfnWndProc = WndProc; //指明函数回调函数地址
wcex.cbClsExtra = 0; //类的附加属性
wcex.cbWndExtra = 0; //窗口的附加属性
wcex.hInstance = hinstance; //窗口实例句柄
wcex.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1)); //应用程序的图标样式
wcex.hCursor = LoadCursor(NULL, IDC_ARROW); //为NULL,是从系统加载一个光标 (窗口的光标样式)
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); //窗口的背景颜色
wcex.lpszMenuName = 0; //窗口的菜单名字
wcex.lpszClassName=szWindowClass; //窗口的类名
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_ICON1));//窗口标题栏的图标
RegisterClassEx(&wcex);//进行注册窗口
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
//参数:窗口句柄,消息,消息参数,消息参数
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_KEYDOWN:
break;
case WM_COMMAND:
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR ipCmdLine, int nCmdShow)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX); //窗口的大小
wcex.style = CS_HREDRAW | CS_VREDRAW;//窗口的风格
wcex.lpfnWndProc = WndProc; //指明函数回调函数地址
wcex.cbClsExtra = 0; //类的附加属性
wcex.cbWndExtra = 0; //窗口的附加属性
wcex.hInstance = hinstance; //窗口实例句柄
wcex.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1)); //应用程序的图标样式
wcex.hCursor = LoadCursor(NULL, IDC_ARROW); //为NULL,是从系统加载一个光标 (窗口的光标样式)
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); //窗口的背景颜色
wcex.lpszMenuName = 0; //窗口的菜单名字
wcex.lpszClassName=szWindowClass; //窗口的类名
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_ICON1));//窗口标题栏的图标
RegisterClassEx(&wcex);//进行注册窗口
hwnd = CreateWindow(szWindowClass, "Wnd Title", WS_OVERLAPPEDWINDOW,
1000, 500, 800, 600, NULL, NULL, hinstance, NULL);
if (!hwnd)
{
return FALSE;
}
ShowWindow(hwnd, SW_SHOW); //设置指定窗口的显示状态
UpdateWindow(hwnd); //更新指定窗口的客户区 (输入要更新的窗口的句柄)
1000, 500, 800, 600, NULL, NULL, hinstance, NULL);
if (!hwnd)
{
return FALSE;
}
ShowWindow(hwnd, SW_SHOW); //设置指定窗口的显示状态
UpdateWindow(hwnd); //更新指定窗口的客户区 (输入要更新的窗口的句柄)
//主消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
if (msg.message == WM_INITDIALOG)
{
MessageBox(0, "窗口初始化中", "Info", MB_OK);
}
TranslateMessage(&msg);//翻译消息
DispatchMessage(&msg);//分发处理消息
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
if (msg.message == WM_INITDIALOG)
{
MessageBox(0, "窗口初始化中", "Info", MB_OK);
}
TranslateMessage(&msg);//翻译消息
DispatchMessage(&msg);//分发处理消息
}
return 0;
}