| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 
 | #include "绘制.h"#include <cmath>
 void 绘制::获取窗口信息()
 {
 if (!GetClientRect(this->目标窗口句柄, &this->内窗口))
 {
 DWORD Error = GetLastError();
 MessageBox(0, L"错误", L"获取内窗口属性失败", 0);
 }
 this->分辨率_宽 = this->内窗口.right - this->内窗口.left;
 this->分辨率_高 = this->内窗口.bottom - this->内窗口.top;
 
 if (!GetWindowRect(this->目标窗口句柄, &this->外窗口))
 {
 MessageBox(0, L"错误", L"获取外窗口属性失败", 0);
 }
 
 this->外窗口宽 = this->外窗口.right - this->外窗口.left;
 this->外窗口高 = this->外窗口.bottom - this->外窗口.top;
 }
 
 void 绘制::绘制矩形框(RECT 矩形)
 {
 PAINTSTRUCT ps;
 HDC hdc = BeginPaint(this->目标窗口句柄, &ps);
 
 
 HPEN hPen = CreatePen(PS_SOLID, 10, RGB(0, 255, 0));
 HGDIOBJ oldPen = SelectObject(hdc, hPen);
 
 
 HBRUSH hBrush = (HBRUSH)GetStockObject(NULL_BRUSH);
 HGDIOBJ oldBrush = SelectObject(hdc, hBrush);
 
 
 Rectangle(hdc, 矩形.left, 矩形.top, 矩形.right, 矩形.bottom);
 
 
 SelectObject(hdc, oldPen);
 SelectObject(hdc, oldBrush);
 
 
 DeleteObject(hPen);
 EndPaint(this->目标窗口句柄, &ps);
 }
 
 void 绘制::画线(int x,int y,DWORD 阵营)
 {
 获取窗口信息();
 HPEN hPen;
 
 if (阵营 == 0)
 {
 hPen = CreatePen(PS_SOLID, 10, RGB(0, 255, 0));
 
 }
 else
 {
 hPen = CreatePen(PS_SOLID, 10, RGB(255, 0, 0));
 }
 HGDIOBJ oldPen = SelectObject(hdc, hPen);
 
 MoveToEx(hdc, this->分辨率_宽 / 2, this->分辨率_高*3/4, NULL);
 
 LineTo(hdc, x, y);
 
 }
 
 void 绘制::绘制字符串(int x,int y)
 {
 PAINTSTRUCT ps;
 HDC hdc = BeginPaint(this->目标窗口句柄, &ps);
 
 
 TCHAR* text = (TCHAR*)L"Hello, Win32 API!";
 
 
 TextOut(hdc, x, y, text, lstrlen(text));
 
 EndPaint(this->目标窗口句柄, &ps);
 }
 
 bool 绘制::世界坐标转为屏幕坐标_非矩阵(对象结构 目标对象结构, 屏幕坐标结构& 目标屏幕坐标结构)
 {
 获取窗口信息();
 FLOAT 高低可视角度 = (FLOAT)(atan2(分辨率_高, 分辨率_宽) * 180 / Π);
 if (fabs(目标对象结构.对象重心的角度差.水平朝向) > 45 || fabs(目标对象结构.对象重心的角度差.垂直朝向) > 高低可视角度)
 {
 目标屏幕坐标结构.x坐标 = (float)(this->分辨率_宽 / 2);
 目标屏幕坐标结构.y坐标 = (float)(this->分辨率_高 * 3 / 4);
 return false;
 }
 int 水平差 = (int)(tan(目标对象结构.对象重心的角度差.水平朝向 * Π / 180) * (分辨率_宽 / 2));
 目标屏幕坐标结构.x坐标 = (float)(分辨率_宽 / 2 + 水平差);
 
 int 高度差 = (int)(tan(目标对象结构.对象重心的角度差.垂直朝向 * Π / 180) * (分辨率_宽) / 2);
 目标屏幕坐标结构.y坐标 = (float)(分辨率_高 / 2 + 高度差);
 
 }
 
 |