MoveToEx, LineTo, Ellipse实例

本文介绍了一个使用WTL框架的绘图实例,通过调用绘图API如MoveToEx、LineTo等函数,实现了一个描绘生命不同阶段的示例程序。程序中定义了两个方法draw_arrow和draw_node,分别用于绘制带箭头的线段和节点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

调用MoveToEx,LineTo,Ellipse函数,实现如下实例:

使用WTL框架,选择Dialog类型,在MainDlg中定义两个private方法:

// draw arrow
void draw_arrow(int nStartX, int nStartY, int nLength) throw()
{
	::MoveToEx(m_hdc, nStartX, nStartY, NULL);
	::LineTo(m_hdc, nStartX + nLength, nStartY);
	::LineTo(m_hdc, nStartX + nLength - 5, nStartY - 5);
	::MoveToEx(m_hdc, nStartX + nLength, nStartY, NULL);
	::LineTo(m_hdc, nStartX + nLength - 5, nStartY + 5);
}
// draw node
void draw_node(int nCenterX, int nCenterY, int nRadius, LPCTSTR szTag, BOOL bCurrent = FALSE) throw()
{
	::Ellipse(m_hdc, nCenterX - nRadius, nCenterY - nRadius,
			nCenterX + nRadius, nCenterY + nRadius);
	if(bCurrent)
		::Ellipse(m_hdc, nCenterX - nRadius*0.4, nCenterY - nRadius*0.4, 
				nCenterX + nRadius*0.4, nCenterY + nRadius*0.4);
	::TextOut(m_hdc, nCenterX - 15, nCenterY + nRadius + 5, szTag, 2);
}

draw_arrow方法的作用是绘制带箭头的线段。draw_node方法的作用是绘制节点,它包含圆形及其下方的标记字符串。参数bCurrent表示本次所绘制的节点是否为当前阶段,本例选择“青年”为当前阶段,该节点的由两个同心圆与普通节点区分开来。

为MainDlg添加对WM_PAINT的消息处理,其响应方法如下所示:

LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	PAINTSTRUCT ps;
	BeginPaint(&ps);
	m_hdc = ps.hdc;
	// draw life stages
	TCHAR* strStages[] = { _T("婴儿"), _T("幼儿"), _T("童年"), _T("少年"),
							_T("青年"), _T("中年"), _T("老年") };
	int nX = 20;
	RECT rc;
	GetClientRect(&rc);
	int nY = rc.bottom / 2;
	int nArrowLength = 50;
	int nRadius = 18;
	int nCurrent = 4; // current is "青年"
	draw_node(nX + nRadius, nY, nRadius, strStages[0], nCurrent == 0);
	for( int i = 0; i < 6; ++i ) {
		draw_arrow(nX + nRadius * 2 + i * nArrowLength + 2 * i * nRadius, nY, nArrowLength);
		draw_node(nX + nRadius * 3 + nArrowLength + i * nArrowLength + 2 * i * nRadius,
				nY, nRadius, strStages[i+1], nCurrent == i + 1);
	} // end for
	EndPaint(&ps);
	return 0;
}


在绘制的时候,除第一个节点之前不带有arrow外,其余6个节点都含有arrow,因此需对第一个节点进行特殊处理,将它的绘制放在for循环之外。整个工程的源码可点击下列链接下载:

http://pan.baidu.com/netdisk/singlepublic?fid=559720_2849936413

#include <Windows.h> // Windows API 核心头文件 #include <commctrl.h> // 通用控件头文件(用于创建按钮等控件) #include <math.h> // 数学函数库(用于箭头计算) #include "aip_commom.h" #define FALSE 0 // 全局变量存储点坐标(使用U2类型) U2 u2_s_position_ax; U2 u2_s_position_ay; U2 u2_s_position_bx; U2 u2_s_position_by; // A点和B点的坐标 BOOL pointsSet = FALSE; // 标记是否已设置点坐标 // 函数声明 void Drawpixel(HDC hdc, U4 originX, U4 originY, U2 x, U2 y); // 绘制点函数 void DrawArrow(HDC hdc, U4 fromX, U4 fromY, U4 toX, U4 toY, U4 arrowSize); // 绘制箭头函数 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // 窗口过程函数 // 程序入口点 U4 WINAPI WinMain( _In_ HINSTANCE hInstance, // 当前实例句柄 _In_opt_ HINSTANCE hPrevInstance, // 先前实例句柄(已废弃) _In_ LPSTR lpCmdLine, // 命令行参数 _In_ U4 nCmdShow) // 窗口显示方式 { const wchar_t CLASS_NAME[] = L"FirstQuadrantWindowClass"; // 窗口类名 // 注册窗口类 WNDCLASS cw = { 0 }; cw.lpfnWndProc = WndProc; // 窗口过程函数 cw.hInstance = hInstance; // 实例句柄 cw.lpszClassName = CLASS_NAME; // 类名 cw.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // 黑色背景 RegisterClass(&cw); // 注册窗口类 // 创建主窗口 HWND hwnd = CreateWindowEx( 0, // 扩展样式 CLASS_NAME, // 窗口类名 L"C语言作业第一题", // 窗口标题 WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME, // 窗口样式(禁用调整大小) CW_USEDEFAULT, CW_USEDEFAULT, // 初始位置 700, 700, // 窗口大小 NULL, NULL, hInstance, NULL); // 父窗口、菜单等 if (hwnd == NULL) return FALSE; // 窗口创建失败则退出 // 创建输入控件(用于输入坐标) // A点X坐标输入 CreateWindow(L"STATIC", L"AX:", WS_CHILD | WS_VISIBLE, 20, 10, 50, 20, hwnd, NULL, hInstance, NULL); CreateWindow(L"EDIT", L"100", WS_CHILD | WS_VISIBLE | WS_BORDER, 70, 10, 50, 20, hwnd, (HMENU)1001, hInstance, NULL); // A点Y坐标输入 CreateWindow(L"STATIC", L"AY:", WS_CHILD | WS_VISIBLE, 130, 10, 20, 20, hwnd, NULL, hInstance, NULL); CreateWindow(L"EDIT", L"100", WS_CHILD | WS_VISIBLE | WS_BORDER, 150, 10, 50, 20, hwnd, (HMENU)1002, hInstance, NULL); // B点X坐标输入 CreateWindow(L"STATIC", L"BX:", WS_CHILD | WS_VISIBLE, 220, 10, 50, 20, hwnd, NULL, hInstance, NULL); CreateWindow(L"EDIT", L"400", WS_CHILD | WS_VISIBLE | WS_BORDER, 270, 10, 50, 20, hwnd, (HMENU)1003, hInstance, NULL); // B点Y坐标输入 CreateWindow(L"STATIC", L"BY:", WS_CHILD | WS_VISIBLE, 330, 10, 20, 20, hwnd, NULL, hInstance, NULL); CreateWindow(L"EDIT", L"400", WS_CHILD | WS_VISIBLE | WS_BORDER, 350, 10, 50, 20, hwnd, (HMENU)1004, hInstance, NULL); // 创建绘制按钮 CreateWindow(L"BUTTON", L"绘制", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 450, 8, 80, 25, hwnd, (HMENU)2000, hInstance, NULL); // 显示窗口 ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); // 消息循环 MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (U4)msg.wParam; // 程序退出 } // 从编辑框获取整数并转换为U2 U2 GetEditUShort(HWND hwnd, U4 ctrlID) { wchar_t text[32]; GetDlgItemText(hwnd, ctrlID, text, 32); // 获取编辑框文本 U4 value = _wtoi(text); // 转换为整数 // 确保值在0-500范围内(坐标系范围) if (value < 0) value = 0; if (value > 500) value = 500; return (U2)value; // 返回无符号短整型 } // 绘制点函数封装 void Drawpixel(HDC hdc, U4 originX, U4 originY, U2 x, U2 y) { // 计算实际绘制位置(将坐标系转换为窗口坐标) U4 winX = originX + x; // X坐标:原点X + 输入X U4 winY = originY - y; // Y坐标:原点Y - 输入Y(因为Y轴向上为正) // 创建红色画刷 HBRUSH hRedBrush = CreateSolidBrush(RGB(255, 0, 0)); // 纯红色 HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc, hRedBrush); // 绘制圆形点(半径为5像素) Ellipse(hdc, winX - 5, winY - 5, winX + 5, winY + 5); // 恢复原始画刷并清理资源 SelectObject(hdc, hOldBrush); DeleteObject(hRedBrush); } 绘制箭头函数 void DrawArrow(HDC hdc, U4 fromX, U4 fromY, U4 toX, U4 toY, U4 arrowSize) { // 计算向量方向(从起点到终点) double dx = toX - fromX; double dy = toY - fromY; // 计算向量长度 double length = sqrt(dx * dx + dy * dy); if (length < 1e-5) return; // 避免除以零(两点重合) // 计算单位向量(方向向量) double ux = dx / length; double uy = dy / length; // 计算箭头端点(从终点回退一点,避免箭头覆盖点) U4 arrowEndX = toX - (U4)(ux * 10); // 回退10像素 U4 arrowEndY = toY - (U4)(uy * 10); // 计算垂直向量(用于箭头两侧) double perpX = -uy; // 垂直向量X分量 double perpY = ux; // 垂直向量Y分量 // 计算箭头两侧点 U4 arrowLeftX = arrowEndX + (U4)(perpX * arrowSize); U4 arrowLeftY = arrowEndY + (U4)(perpY * arrowSize); U4 arrowRightX = arrowEndX - (U4)(perpX * arrowSize); U4 arrowRightY = arrowEndY - (U4)(perpY * arrowSize); // 绘制箭头主体(从起点到终点) MoveToEx(hdc, fromX, fromY, NULL); LineTo(hdc, toX, toY); // 绘制箭头两侧(从终点到两侧点) MoveToEx(hdc, toX, toY, NULL); LineTo(hdc, arrowLeftX, arrowLeftY); MoveToEx(hdc, toX, toY, NULL); LineTo(hdc, arrowRightX, arrowRightY); } // 窗口过程函数(处理窗口消息) LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_COMMAND: { // 处理控件消息 if (LOWORD(wParam) == 2000) { // 绘制按钮被点击 // 获取用户输入的坐标值 u2_s_position_ax = GetEditUShort(hwnd, 1001); // A点X坐标 u2_s_position_ay = GetEditUShort(hwnd, 1002); // A点Y坐标 u2_s_position_bx = GetEditUShort(hwnd, 1003); // B点X坐标 u2_s_position_by = GetEditUShort(hwnd, 1004); // B点Y坐标 pointsSet = TRUE; // 标记已设置点 InvalidateRect(hwnd, NULL, TRUE); // 请求重绘窗口 } break; } case WM_PAINT: { // 窗口需要重绘 PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); // 开始绘制 RECT rect; GetClientRect(hwnd, &rect); // 获取客户区大小 U4 height = rect.bottom - rect.top; // 窗口高度 // 设置坐标系参数 U4 originX = 50; // 原点X坐标(距离窗口左侧) U4 originY = height - 80; // 原点Y坐标(距离窗口底部) U4 axisLength = 500; // 坐标轴长度 // 创建白色画笔用于坐标轴 HPEN hAxisPen = CreatePen(PS_SOLID, 2, RGB(255, 255, 255)); HPEN hOldPen = (HPEN)SelectObject(hdc, hAxisPen); // 绘制X轴(从原点到右侧) MoveToEx(hdc, originX, originY, NULL); LineTo(hdc, originX + axisLength, originY); // 绘制Y轴(从原点上侧) MoveToEx(hdc, originX, originY, NULL); LineTo(hdc, originX, originY - axisLength); // 绘制X轴箭头(右侧) MoveToEx(hdc, originX + axisLength, originY, NULL); LineTo(hdc, originX + axisLength - 10, originY - 5); // 上侧箭头线 MoveToEx(hdc, originX + axisLength, originY, NULL); LineTo(hdc, originX + axisLength - 10, originY + 5); // 下侧箭头线 // 绘制Y轴箭头(上侧) MoveToEx(hdc, originX, originY - axisLength, NULL); LineTo(hdc, originX - 5, originY - axisLength + 10); // 左侧箭头线 MoveToEx(hdc, originX, originY - axisLength, NULL); LineTo(hdc, originX + 5, originY - axisLength + 10); // 右侧箭头线 // 绘制刻度(每50像素一个刻度) for (U4 i = 1; i <= 10; i++) { // X轴刻度 U4 pos = originX + i * 50; MoveToEx(hdc, pos, originY - 5, NULL); LineTo(hdc, pos, originY + 5); // Y轴刻度 MoveToEx(hdc, originX - 5, originY - i * 50, NULL); LineTo(hdc, originX + 5, originY - i * 50); } // 标注坐标轴 SetTextColor(hdc, RGB(255, 255, 255)); // 白色文本 SetBkColor(hdc, RGB(0, 0, 0)); // 黑色背景 TextOut(hdc, originX + axisLength - 20, originY + 20, L"X", 1); // X轴标签 TextOut(hdc, originX - 20, originY - axisLength + 10, L"Y", 1); // Y轴标签 TextOut(hdc, originX - 10, originY + 5, L"O", 1); // 原点标签 // 如果设置了点,绘制点和连线 if (pointsSet) { // 计算实际绘制位置(窗口坐标) U4 winAx = originX + u2_s_position_ax; // A点X坐标 U4 winAy = originY - u2_s_position_ay; // A点Y坐标 U4 winBx = originX + u2_s_position_bx; // B点X坐标 U4 winBy = originY - u2_s_position_by; // B点Y坐标 // 使用封装函数绘制点A和点B Drawpixel(hdc, originX, originY, u2_s_position_ax, u2_s_position_ay); // 绘制A点 Drawpixel(hdc, originX, originY, u2_s_position_bx, u2_s_position_by); // 绘制B点 // 创建红色画笔用于连接线 HPEN hRedPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0)); SelectObject(hdc, hRedPen); // 使用箭头绘制函数(从A到B) DrawArrow(hdc, winAx, winAy, winBx, winBy, 8); // 箭头大小8像素 // 标记点A SetTextColor(hdc, RGB(255, 200, 200)); // 浅红色文本 SetBkMode(hdc, TRANSPARENT); // 透明背景 TextOut(hdc, winAx + 8, winAy - 8, L"A", 1); // A点标签 // 标记点B SetTextColor(hdc, RGB(180, 220, 255)); // 浅蓝色文本 TextOut(hdc, winBx + 8, winBy - 8, L"B", 1); // B点标签 // 清理画笔资源 SelectObject(hdc, hRedPen); DeleteObject(hRedPen); } // 恢复原始画笔并清理资源 SelectObject(hdc, hOldPen); DeleteObject(hAxisPen); EndPaint(hwnd, &ps); // 结束绘制 return 0; } case WM_DESTROY: // 窗口销毁消息 PostQuitMessage(0); // 退出消息循环 return 0; } return DefWindowProc(hwnd, msg, wParam, lParam); // 默认消息处理 } 取消掉该代码中绘制箭头的功能
07-25
#include <Windows.h> #include <commctrl.h> #include <math.h> // 添加数学库用于箭头计算 // 全局变量存储点坐标(使用unsigned short类型) static unsigned short Ax = 0, Ay = 0, Bx = 0, By = 0; static BOOL pointsSet = FALSE; // 声明绘制点函数 void Drawpixel(HDC hdc, int originX, int originY, unsigned short x, unsigned short y); // 声明绘制箭头函数 void DrawArrow(HDC hdc, int fromX, int fromY, int toX, int toY, int arrowSize); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain( In HINSTANCE hInstance, In_opt HINSTANCE hPrevInstance, In LPSTR lpCmdLine, In int nCmdShow) { const wchar_t CLASS_NAME[] = L"FirstQuadrantWindowClass"; WNDCLASS wc = { 0 }; wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.lpszClassName = CLASS_NAME; wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); RegisterClass(&wc); HWND hwnd = CreateWindowEx( 0, CLASS_NAME, L"第一象限坐标系", WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME, CW_USEDEFAULT, CW_USEDEFAULT, 636, 700, NULL, NULL, hInstance, NULL); if (hwnd == NULL) return 0; // 创建输入控件 CreateWindow(L"STATIC", L"A点 X:“, WS_CHILD | WS_VISIBLE, 20, 10, 50, 20, hwnd, NULL, hInstance, NULL); CreateWindow(L"EDIT”, L"100", WS_CHILD | WS_VISIBLE | WS_BORDER, 70, 10, 50, 20, hwnd, (HMENU)1001, hInstance, NULL); CreateWindow(L"STATIC", L"Y:“, WS_CHILD | WS_VISIBLE, 130, 10, 20, 20, hwnd, NULL, hInstance, NULL); CreateWindow(L"EDIT”, L"100", WS_CHILD | WS_VISIBLE | WS_BORDER, 150, 10, 50, 20, hwnd, (HMENU)1002, hInstance, NULL); CreateWindow(L"STATIC", L"B点 X:“, WS_CHILD | WS_VISIBLE, 220, 10, 50, 20, hwnd, NULL, hInstance, NULL); CreateWindow(L"EDIT”, L"400", WS_CHILD | WS_VISIBLE | WS_BORDER, 270, 10, 50, 20, hwnd, (HMENU)1003, hInstance, NULL); CreateWindow(L"STATIC", L"Y:“, WS_CHILD | WS_VISIBLE, 330, 10, 20, 20, hwnd, NULL, hInstance, NULL); CreateWindow(L"EDIT”, L"400", WS_CHILD | WS_VISIBLE | WS_BORDER, 350, 10, 50, 20, hwnd, (HMENU)1004, hInstance, NULL); CreateWindow(L"BUTTON", L"绘制", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 450, 8, 80, 25, hwnd, (HMENU)2000, hInstance, NULL); ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } // 从编辑框获取整数并转换为unsigned short unsigned short GetEditUShort(HWND hwnd, int ctrlID) { wchar_t text[32]; GetDlgItemText(hwnd, ctrlID, text, 32); int value = _wtoi(text); // 确保值在0-500范围内 if (value < 0) value = 0; if (value > 500) value = 500; return (unsigned short)value; } // 绘制点函数封装 void Drawpixel(HDC hdc, int originX, int originY, unsigned short x, unsigned short y) { // 计算实际绘制位置 int winX = originX + x; int winY = originY - y; // 绘制点(统一使用红色) HBRUSH hRedBrush = CreateSolidBrush(RGB(255, 0, 0)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc, hRedBrush); Ellipse(hdc, winX - 5, winY - 5, winX + 5, winY + 5); // 恢复对象并清理 SelectObject(hdc, hOldBrush); DeleteObject(hRedBrush); } // 绘制箭头函数 void DrawArrow(HDC hdc, int fromX, int fromY, int toX, int toY, int arrowSize) { // 计算向量方向 double dx = toX - fromX; double dy = toY - fromY; // 计算向量长度 double length = sqrt(dx * dx + dy * dy); if (length < 1e-5) return; // 避免除以零 // 计算单位向量 double ux = dx / length; double uy = dy / length; // 计算箭头端点(从终点回退一点) int arrowEndX = toX - (int)(ux * 10); // 回退10像素 int arrowEndY = toY - (int)(uy * 10); // 计算垂直向量(用于箭头两侧) double perpX = -uy; double perpY = ux; // 计算箭头两侧点 int arrowLeftX = arrowEndX + (int)(perpX * arrowSize); int arrowLeftY = arrowEndY + (int)(perpY * arrowSize); int arrowRightX = arrowEndX - (int)(perpX * arrowSize); int arrowRightY = arrowEndY - (int)(perpY * arrowSize); // 绘制箭头主体 MoveToEx(hdc, fromX, fromY, NULL); LineTo(hdc, toX, toY); // 绘制箭头两侧 MoveToEx(hdc, toX, toY, NULL); LineTo(hdc, arrowLeftX, arrowLeftY); MoveToEx(hdc, toX, toY, NULL); LineTo(hdc, arrowRightX, arrowRightY); } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_COMMAND: { if (LOWORD(wParam) == 2000) { // 绘制按钮 // 获取用户输入(unsigned short类型) Ax = GetEditUShort(hwnd, 1001); Ay = GetEditUShort(hwnd, 1002); Bx = GetEditUShort(hwnd, 1003); By = GetEditUShort(hwnd, 1004); pointsSet = TRUE; InvalidateRect(hwnd, NULL, TRUE); } break; } case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); RECT rect; GetClientRect(hwnd, &rect); int height = rect.bottom - rect.top; // 设置坐标系参数 int originX = 50; int originY = height - 80; int axisLength = 500; // 绘制坐标轴 HPEN hAxisPen = CreatePen(PS_SOLID, 2, RGB(255, 255, 255)); HPEN hOldPen = (HPEN)SelectObject(hdc, hAxisPen); MoveToEx(hdc, originX, originY, NULL); LineTo(hdc, originX + axisLength, originY); MoveToEx(hdc, originX, originY, NULL); LineTo(hdc, originX, originY - axisLength); // 绘制箭头 MoveToEx(hdc, originX + axisLength, originY, NULL); LineTo(hdc, originX + axisLength - 10, originY - 5); MoveToEx(hdc, originX + axisLength, originY, NULL); LineTo(hdc, originX + axisLength - 10, originY + 5); MoveToEx(hdc, originX, originY - axisLength, NULL); LineTo(hdc, originX - 5, originY - axisLength + 10); MoveToEx(hdc, originX, originY - axisLength, NULL); LineTo(hdc, originX + 5, originY - axisLength + 10); // 绘制刻度 for (int i = 1; i <= 10; i++) { int pos = originX + i * 50; MoveToEx(hdc, pos, originY - 5, NULL); LineTo(hdc, pos, originY + 5); MoveToEx(hdc, originX - 5, originY - i * 50, NULL); LineTo(hdc, originX + 5, originY - i * 50); } // 标注坐标轴 SetTextColor(hdc, RGB(255, 255, 255)); SetBkColor(hdc, RGB(0, 0, 0)); TextOut(hdc, originX + axisLength - 20, originY + 20, L"X", 1); TextOut(hdc, originX - 20, originY - axisLength + 10, L"Y", 1); TextOut(hdc, originX - 10, originY + 5, L"O", 1); // 如果设置了点,绘制点和连线 if (pointsSet) { // 计算实际绘制位置 int winAx = originX + Ax; int winAy = originY - Ay; int winBx = originX + Bx; int winBy = originY - By; // 使用封装函数绘制点A和点B Drawpixel(hdc, originX, originY, Ax, Ay); Drawpixel(hdc, originX, originY, Bx, By); // 绘制红色连接线(带箭头) HPEN hRedPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0)); SelectObject(hdc, hRedPen); // 使用箭头绘制函数 DrawArrow(hdc, winAx, winAy, winBx, winBy, 8); // 标记点A SetTextColor(hdc, RGB(255, 200, 200)); // 浅红色文本 SetBkMode(hdc, TRANSPARENT); // 透明背景 TextOut(hdc, winAx + 8, winAy - 8, L"A", 1); // 标记点B SetTextColor(hdc, RGB(180, 220, 255)); // 浅蓝色文本 TextOut(hdc, winBx + 8, winBy - 8, L"B", 1); // 清理资源 SelectObject(hdc, hRedPen); DeleteObject(hRedPen); } // 恢复并清理资源 SelectObject(hdc, hOldPen); DeleteObject(hAxisPen); EndPaint(hwnd, &ps); return 0; } case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, msg, wParam, lParam); } 给该代码增加详细的注释
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值