画动画

#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 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;
}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部