[C++] 纯文本查看 复制代码 #include <windows.h> //插入Windows.h头文件,这是一个windows函数的支持库
#include <stdio.h> //插入stdio.h头文件,这是一个C语言函数的支持库
#include <iostream> //插入C++输入输出支持库
#pragma comment(lib, "user32.lib") //静态库
#pragma comment(lib, "gdi32.lib")//静态库
using namespace std; //定义命名空间
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//定义CALLBACK函数回调,
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) //Windows 窗口的入口,并且传入参数
{
/*
1.创建类
2.注册类
3.创建窗口
4.显示窗口
5.更新窗口
6.消息循环
*/
static TCHAR szAppName[] = TEXT("Window");
HWND hwnd;
MSG msg;
WNDCLASS wndclass; //WNDCLASS structure 窗口的结构信息,包含窗口的属性和参数
wndclass.style = CS_HREDRAW | CS_VREDRAW;//窗口样式的类型
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 = szAppName;//窗口的类名
RegisterClass(&wndclass);//注册窗口类
hwnd = CreateWindow(szAppName,//窗口类名
TEXT("窗口标题"),//窗口标题
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
600,
400,
NULL,
NULL,
hInstance,
NULL);
/*------------------------动画开始执行----------------------------------*/
AnimateWindow(hwnd, 2000, AW_CENTER); //设置窗口动画
/*------------------------显示窗口----------------------------------*/
ShowWindow(hwnd, iCmdShow);//显示窗口
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)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch (message)
{
case WM_CREATE:
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);//绘画文字
GetClientRect(hwnd, &rect);
DrawText(hdc, TEXT("AnimateWindow "), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);//退出窗口
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);//调用默认窗口过程
} |