CChartAxisLabel类用来绘制轴标签,上、下、左、右都可以根据实际需要设置对应的轴标签。它处于该控件的区域,如下图所示:

CChartAxisLabel类的头文件。

#if !defined(AFX_CHARTAXISLABEL_H__0E5519C8_A2F4_4CED_9681_32A56B25D0C5__INCLUDED_)
#define AFX_CHARTAXISLABEL_H__0E5519C8_A2F4_4CED_9681_32A56B25D0C5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ChartObject.h"
#include "ChartString.h"
class CChartAxis;
class CChartAxisLabel : public CChartObject
{
friend CChartAxis;
public:
void SetText(const TChartString& NewText);
TChartString GetText() const { return m_strLabelText; }
void SetFont(int nPointSize, const TChartString& strFaceName);
CChartAxisLabel(CChartCtrl* pParent, bool bHorizontal);
virtual ~CChartAxisLabel();
private:
void SetPosition(int LeftBorder, int TopBorder, CDC *pDC);
void Draw(CDC* pDC);
CSize GetSize(CDC* pDC) const;
bool m_bIsHorizontal; // Specifies if the axis is horizontal or not
int m_iFontSize;
TChartString m_strFontName;
TChartString m_strLabelText;
};
#endif // !defined(AFX_CHARTAXISLABEL_H__0E5519C8_A2F4_4CED_9681_32A56B25D0C5__INCLUDED_)

CChartAxisLabel类的源文件。

#include "stdafx.h"
#include "ChartAxisLabel.h"
#include "ChartCtrl.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CChartAxisLabel::CChartAxisLabel(CChartCtrl* pParent, bool bHorizontal):CChartObject(pParent)
{
m_bIsHorizontal = bHorizontal;
m_iFontSize = ;
m_strFontName = _T("Microsoft Sans Serif");
m_strLabelText = _T("");
}
CChartAxisLabel::~CChartAxisLabel()
{
}
void CChartAxisLabel::SetText(const TChartString& NewText)
{
m_strLabelText = NewText;
m_pParent->RefreshCtrl();
}
void CChartAxisLabel::SetFont(int nPointSize, const TChartString& strFaceName)
{
m_iFontSize = nPointSize;
m_strFontName = strFaceName;
m_pParent->RefreshCtrl();
}
CSize CChartAxisLabel::GetSize(CDC *pDC) const
{
CSize LabelSize;
LabelSize.cx = ;
LabelSize.cy = ;
if (!m_bIsVisible)
return LabelSize;
if (!pDC->GetSafeHdc())
return LabelSize;
if (m_strLabelText == _T(""))
return LabelSize;
CFont NewFont;
CFont* pOldFont;
NewFont.CreatePointFont(m_iFontSize,m_strFontName.c_str(),pDC);
pOldFont = pDC->SelectObject(&NewFont);
LabelSize = pDC->GetTextExtent(m_strLabelText.c_str());
LabelSize.cx += ;
LabelSize.cy += ;
if (!m_bIsHorizontal)
{
int Width = LabelSize.cy;
int Height = LabelSize.cx;
LabelSize.cx = Width;
LabelSize.cy = Height;
}
pDC->SelectObject(pOldFont);
DeleteObject(NewFont);
return LabelSize;
}
void CChartAxisLabel::Draw(CDC *pDC)
{
if (!m_bIsVisible)
return;
if (!pDC->GetSafeHdc())
return;
if (m_strLabelText == _T(""))
return;
int iPrevMode = pDC->SetBkMode(TRANSPARENT);
COLORREF OldColor = pDC->SetTextColor(m_ObjectColor);
CFont NewFont;
NewFont.CreatePointFont(m_iFontSize,m_strFontName.c_str(),pDC);
CFont* pOldFont;
if (!m_bIsHorizontal)
{
LOGFONT LogFont;
NewFont.GetLogFont(&LogFont);
LogFont.lfOrientation = ;
LogFont.lfEscapement = ;
CFont VertFont;
VertFont.CreateFontIndirect(&LogFont);
pOldFont = pDC->SelectObject(&VertFont);
pDC->ExtTextOut(m_ObjectRect.left + ,m_ObjectRect.top,
ETO_CLIPPED,NULL,m_strLabelText.c_str(),NULL);
pDC->SelectObject(pOldFont);
DeleteObject(VertFont);
DeleteObject(NewFont);
}
else
{
pOldFont = pDC->SelectObject(&NewFont);
pDC->ExtTextOut(m_ObjectRect.left,m_ObjectRect.top + ,
ETO_CLIPPED,NULL,m_strLabelText.c_str(),NULL);
pDC->SelectObject(pOldFont);
DeleteObject(NewFont);
}
pDC->SetBkMode(iPrevMode);
pDC->SetTextColor(OldColor);
}
void CChartAxisLabel::SetPosition(int LeftBorder, int TopBorder, CDC *pDC)
{
CSize NewSize = GetSize(pDC);
CRect NewRect;
NewRect.top = TopBorder;
NewRect.bottom = TopBorder + NewSize.cy;
NewRect.left = LeftBorder;
NewRect.right = LeftBorder + NewSize.cx;
CChartObject::SetRect(NewRect);
}

CChartAxisLabel类在CChartAxis类中设定最终绘制的位置。

ChartCtrl源码剖析之——CChartAxisLabel类的更多相关文章

  1. ChartCtrl源码剖析之——CChartObject类

    首先,做一些简单的铺垫,目前针对ChartCtrl源码的剖析只针对V.15版本.名义上说是剖析,倒不如说是记录下自己针对该控件的理解,非常感谢Cedric Moonen大神,一切的功劳与掌声都该赠予给 ...

  2. ChartCtrl源码剖析之——CChartAxis类

    CChartAxis类用来绘制波形控件的坐标轴,这个源码相对较复杂,当初阅读的时候耗费了不少精力来理解源码中的一些实现细节. CChartAxis类的头文件. #if !defined(AFX_CHA ...

  3. ChartCtrl源码剖析之——CChartScrollBar类

    CChartScrollBar类用来针对每个轴的数据进行滚动,将那些不在当前区域内的数据通过滚动展示出来. CChartScrollBar类的头文件. #pragma once class CChar ...

  4. ChartCtrl源码剖析之——CChartTitle类

    CChartTitle类顾名思义,该类用来绘制波形控件的标题,它处于该控件的区域,如下图所示: CChartTitle类的头文件. #if !defined(AFX_CHARTTITLE_H__499 ...

  5. ChartCtrl源码剖析之——CChartLegend类

    CChartLegend类用来绘制每一个波形的描述信息,它处于该控件的区域,如下图所示: CChartLegend类的头文件. #if !defined(AFX_CHARTLEGEND_H__CD72 ...

  6. ChartCtrl源码剖析之——CChartGrid类

    CChartGrid类用来绘制波形区域中的表格,当绘制波形时波形就显示在这些表格上面.它处于该控件的区域,如下图所示: CChartGrid类的头文件. #if !defined(AFX_CHARTG ...

  7. PART(Persistent Adaptive Radix Tree)的Java实现源码剖析

    论文地址 Adaptive Radix Tree: https://db.in.tum.de/~leis/papers/ART.pdf Persistent Adaptive Radix Tree: ...

  8. 老李推荐:第6章3节《MonkeyRunner源码剖析》Monkey原理分析-事件源-事件源概览-命令翻译类

    老李推荐:第6章3节<MonkeyRunner源码剖析>Monkey原理分析-事件源-事件源概览-命令翻译类   每个来自网络的字串命令都需要进行解析执行,只是有些是在解析的过程中直接执行 ...

  9. WorldWind源码剖析系列:影像存储类ImageStore、Nlt影像存储类NltImageStore和WMS影像存储类WmsImageStore

    影像存储类ImageStore 影像存储类ImageStore提供了计算本地影像路径和远程影像影像URL访问的各种接口,是WmsImageStore类和NltImageStore类的基类.当划分完层次 ...

随机推荐

  1. [NOIP1998] 提高组 洛谷P1013 进制位

    题目描述 著名科学家卢斯为了检查学生对进位制的理解,他给出了如下的一张加法表,表中的字母代表数字. 例如: L K V E L L K V E K K V E KL V V E KL KK E E K ...

  2. 从零开始写STL—模板元编程之any

    any class any; (since C++17) The class any describes a type-safe container for single values of any ...

  3. HDU 5668 Circle

    中国剩余定理. 可以手动模拟一下每一次开始的人的编号和结束的人的编号. 每次删掉一个人,对剩下的人重新编号. 这样一次模拟下来,可以得到n个方程 形如:(u[i]+k)%(n-i+1)=v[i] 化简 ...

  4. Distinct Subsequences (dp)

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  5. [Bzoj1499][NOI2005]瑰丽华尔兹[简单DP]

    1499: [NOI2005]瑰丽华尔兹 Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 1714  Solved: 1042[Submit][Status ...

  6. 51nod 马拉松30 C(构二分图+状压dp)

    题意 分析 考虑一个图能被若干简单环覆盖,那么一定是每个点恰好一个出度,恰好一个出度 于是类似最小路径覆盖的处理,我们可以把每个点拆成2个点i和i',如果有一条边(i,j),那么将i和j'连起来 那么 ...

  7. Java的对象和类

    以下内容引用自http://wiki.jikexueyuan.com/project/java/object-classes.html: 一.概述 Java是一种面向对象的语言.作为一种具有面向对象特 ...

  8. jmete命令行停止失败的原因分析

    1.在jmeter的master机器上使用如下方式启动远程IP地址2.2.2.2,3.3.3.3上的jmeter slave服务,执行到最后生成报告: sh apache-jmeter-3.1/bin ...

  9. 实例 mount新硬盘方法

    0.建立挂载文件夹: mkdir /mnt/sdb1 1 .查看新硬盘: fdisk -l 2. 硬盘分区: fdisk /dev/sdb1 根据提示,依次输入 n, p, 1, 以及两次回车,然后是 ...

  10. 提示:“请检查浏览器代理设置”/xx-net

    1.删除已导入的证书文件(运行certmgr.msc和certlm.msc,然后自己找到xxnet删),2.更新3.3.1(或是自己找到那行代码取消注释,楼下有人提及)3.删除data文件夹(下的ce ...