#include “stdafx.h”
#include “EatPeasPproject.h”
#include"GMap.h"
#define MAX_LOADSTRING 100
#define WWIDTH 700 //宽
#define WHEIGHT 740 //高
#define PI 3.1415926
// 全局变量:
HINSTANCE hInst; // 当前实例
HWND g_hwnd; //当前窗体
WCHAR szTitle[MAX_LOADSTRING]; // 标题栏文本
WCHAR szWindowClass[MAX_LOADSTRING]; // 主窗口类名
// 此代码模块中包含的函数的前向声明:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY wWinMain(In HINSTANCE hInstance,
In_opt HINSTANCE hPrevInstance,
In LPWSTR lpCmdLine,
In int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: 在此放置代码。
// 初始化全局字符串
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_EATPEASPPROJECT, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// 执行应用程序初始化:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_EATPEASPPROJECT));
MSG msg;
int iFrame = 1; //当前帧数
int dwTime = GetTickCount(); //控制帧数时间
// 主消息循环:
while (1)
{
if (PeekMessage(&msg,nullptr,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
HDC hdc = GetDC(g_hwnd);
//画动画
int centerX = WWIDTH / 2;
int centerY = WHEIGHT / 2;
int r = 100;
if (GetTickCount()-dwTime > 260)
{
dwTime = GetTickCount();
}
else
{
continue;
}
//填充白块
std::shared_ptr<HBRUSH__> br(CreateSolidBrush(RGB(255, 255, 255)), [](HBRUSH br) {DeleteObject(br); }); //智能指针
RECT rect;
GetClientRect(g_hwnd, &rect); //全屏刷新
FillRect(hdc, &rect, br.get());
if (iFrame % 2 == 0)
{
//画第二帧和第四帧
int x1, y1, x2, y2;
x1 = centerX - r*cos(PI*0.25f); //起始点的横坐标
y1 = centerY - r*cos(PI*0.25f);
x2 = centerX - r*cos(PI*0.25f); //起始点的横坐标
y2 = centerY + r*cos(PI*0.25f);
Arc(hdc, centerX - r, centerY - r, centerX + r, centerY + r, x2, y2, x1, y1);
MoveToEx(hdc, x1, y1, nullptr);
LineTo(hdc, centerX, centerY);
MoveToEx(hdc, x2, y2, nullptr);
LineTo(hdc, centerX, centerY);
}
else if(iFrame % 3 == 0)
{
//第三帧
Arc(hdc, centerX - r, centerY - r, centerX + r, centerY + r, centerX, centerY + r, centerX, centerY - r);
MoveToEx(hdc, centerX, centerY - r, nullptr);
LineTo(hdc, centerX, centerY + r);
}
else
{
//第一和第五帧
Ellipse(hdc, centerX - r, centerY - r, centerX + r, centerY + r); //画圆
MoveToEx(hdc, centerX - r, centerY, nullptr); //把点移到最左边
LineTo(hdc, centerX, centerY); //左边到中心点
}
iFrame++;
ReleaseDC(g_hwnd, hdc);
}
return (int) msg.wParam;
}
//
// 函数: MyRegisterClass()
//
// 目的: 注册窗口类。
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEXW 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_EATPEASPPROJECT));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_EATPEASPPROJECT);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassExW(&wcex);
}
//
// 函数: InitInstance(HINSTANCE, int)
//
// 目的: 保存实例句柄并创建主窗口
//
// 注释:
//
// 在此函数中,我们在全局变量中保存实例句柄并
// 创建和显示主程序窗口。
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // 将实例句柄存储在全局变量中
HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
0, 0, WWIDTH, WHEIGHT, nullptr, nullptr, hInstance, nullptr); //CW_USEDEFAULT, 0(窗体相对于屏幕的坐标位置)
if (!hWnd)
{
return FALSE;
}
g_hwnd = hWnd;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}