📄 cgraphdlg.cpp
字号:
// CGraphDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CVenus.h"
#include "MainFrm.h"
#include "CGraphDlg.h"
#include "Axes.h"
#include "Axis.h"
#include "AxisTitle.h"
#include "Series.h"
#include "FastLineSeries.h"
#include "VolumeSeries.h"
#include "Pen.h"
#include "Printer.h"
#include "Titles.h"
#include "Strings.h"
#include "Panel.h"
#include "Canvas.h"
#include "Export.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCGraphDlg dialog
char cGraphColor[][16] =
{
" 32768 1\n",
" 8388736 1\n",
" 16711808 1\n",
" 12615680 1\n",
" 16744448 1\n",
" 16711935 1\n",
" 16711680 1\n", // 0xff0000
" 65280 1\n", // Ox00ff00
" 16776960 1\n", // 0xffff00
" 16711935 1\n", // 0xff00ff
" 65535 1\n", // 0x00ffff
" 8388863 1\n",
" 32896 1\n",
" 4227327 1\n",
" 8388672 1\n",
" 8421631 1\n",
" 4194432 1\n",
" 8421440 1\n"
};
int iGraphColorNum = sizeof(cGraphColor)/sizeof(cGraphColor[0]);
CCGraphDlg::CCGraphDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCGraphDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCGraphDlg)
m_pParent = pParent;
m_nID = CCGraphDlg::IDD;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pMinMax = NULL;
}
CCGraphDlg::~CCGraphDlg()
{
if(m_pMinMax != NULL)
{
delete m_pMinMax;
}
}
/*************************************************************************
*
* Create()
*
* 功 能: 创立对话框
*
* 参 数: 无
*
* 返回值: 无
*************************************************************************/
BOOL CCGraphDlg::Create()
{
// return CDialog::Create(m_nID, m_pParent);
return CDialog::Create(CCGraphDlg::IDD, m_pParent);
}
void CCGraphDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCGraphDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCGraphDlg, CDialog)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CCGraphDlg)
ON_WM_SIZE()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCGraphDlg message handlers
BOOL CCGraphDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_hAccel = LoadAccelerators(AfxGetInstanceHandle( ),
MAKEINTRESOURCE(IDR_MAINFRAME));
CMenu* pSysMenu = GetSystemMenu(FALSE); // 得到系统菜单的指针
if (pSysMenu != NULL)
{
pSysMenu->ModifyMenu(0,MF_BYPOSITION);
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// 初始化TeeChart
CRect rc;
rc.left = 10;
rc.top = 11;
rc.bottom = 419;
rc.right = 470;
m_chart.Create(WS_CHILD | WS_VISIBLE, rc, 30000, this, "");
SetChartPos();
m_chart.InitChart(0x03);
m_pTipDlg = new CTipDlg;
m_pTipDlg->Create();
return TRUE; // return TRUE unless you set the focus to a control
}
/*************************************************************************
*
* MoveTipDlg()
*
* 功 能: 移动提示对话框
*
* 参 数: CRect DlgLoc: 鼠标位置
* CString tipInfo: 提示信息
*
* 返回值: 无
*
*************************************************************************/
void CCGraphDlg::MoveTipDlg(CRect DlgLoc, CString tipInfo)
{
m_pTipDlg->SetTipInfo(tipInfo, DlgLoc);
}
/*************************************************************************
*
* HideTipDlg()
*
* 功 能: 隐藏提示对话框
*
* 参 数: 无
*
* 返回值: 无
*
*************************************************************************/
void CCGraphDlg::HideTipDlg()
{
m_pTipDlg->ShowWindow(SW_HIDE);
}
/*************************************************************************
*
* SetChartPos()
*
* 功 能: 设置图片位置
*
* 参 数: 无
*
* 返回值: 无
*
*************************************************************************/
void CCGraphDlg::SetChartPos()
{
CRect rc;
if(m_chart.m_hWnd != NULL)
{
GetClientRect(&rc);
m_chart.SetWindowPos(NULL, rc.left + 1, rc.top + 1, rc.Width() - 2, rc.Height() - 2, NULL);
}
}
/*************************************************************************
*
* OnSize()
*
* 功 能: 响应改变框架尺寸
*
* 参 数: UINT nType, int cx, int cy: MFC定义
*
* 返回值: 无
*
*************************************************************************/
void CCGraphDlg::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
SetChartPos();
}
/*************************************************************************
*
* DrawGraph()
*
* 功 能: 绘制一幅图形
*
* 参 数: sGraphData *pGraphData: 数据
* int iPrevNum: 上一幅图的线条数
*
* 返回值: 无
*
*************************************************************************/
void CCGraphDlg::DrawGraph(sGraphData *pGraphData, int iPrevNum, int iGraphLoc)
{
BOOL bFirst = TRUE;
POSITION pos;
double x, y;
CString str;
double _minX = 0xFFFF, _minY = 0xFFFF, _maxX = 0, _maxY = 0;
if(pGraphData == NULL) return;
if(((CCVenusApp*)AfxGetApp())->m_btMain == 0x02)
m_chart.GetPanel().SetMarginRight(26);
// str = pGraphData->strCaption.Right(pGraphData->strCaption.GetLength() - 3);
str = pGraphData->strCaption;
str.Replace(_T("$$"),_T(""));
m_chart.GetAxis().GetBottom().GetTitle().SetCaption(str);
m_chart.ClearUp();
for(int i = 0; i < pGraphData->iLineNum; i++)
{
m_chart.AddSeries(6);
m_chart.GetSeries(i).SetCursor(-21);
m_chart.GetSeries(i).GetAsFastLine().GetLinePen().SetWidth(pGraphData->pLineParm[i].iWidth);
m_chart.GetSeries(i).GetAsFastLine().GetLinePen().SetColor(pGraphData->pLineParm[i].cColor);
pos = pGraphData->pslData[i].GetHeadPosition();
while(pos != NULL)
{
str = pGraphData->pslData[i].GetNext(pos);
if(bFirst)
{
x = atof(str);
bFirst = FALSE;
}
else
{
y = atof(str);
bFirst = TRUE;
}
if(bFirst)
{
m_chart.GetSeries(i).GetAsFastLine().AddRealTime(x, y, "", RGB(0,0,0));
if(_minX > x) _minX = x;
if(_maxX < x) _maxX = x;
if(_minY > y) _minY = y;
if(_maxY < y) _maxY = y;
}
}
}
m_chart.GetAxis().GetBottom().SetMinMax(_minX, _maxX);
m_chart.GetAxis().GetLeft().SetMinMax(_minY, _maxY);
if(m_pMinMax == NULL)
{
m_pMinMax = new double[4];
}
m_pMinMax[0] = _minX;
m_pMinMax[1] = _maxX;
m_pMinMax[2] = _minY;
m_pMinMax[3] = _maxY;
m_chart.DrawLineMark(TRUE);
// m_chart.OnAfterDrawTChart();
}
/*************************************************************************
*
* PrintChart()
*
* 功 能: 打印图形
*
* 参 数: 无
*
* 返回值: 无
*
*************************************************************************/
void CCGraphDlg::PrintChart()
{
long width = m_chart.GetPrinter().GetPageWidth();
long height = m_chart.GetPrinter().GetPageHeight();
CString str;
SYSTEMTIME time;
GetLocalTime(&time);
str.Format("%s %d%s%02d%s%02d %s %02d%s%02d%s%02d", "时间:", time.wYear, "/", time.wMonth, "/", time.wDay, "-",
time.wHour, ":", time.wMinute, ":", time.wSecond);
COleVariant title((CString)str, VT_BSTR);
((CTChart*)GetDlgItem(IDC_CHART1))->GetHeader().GetText().Clear();
((CTChart*)GetDlgItem(IDC_CHART1))->GetHeader().GetText().Add(title);
((CTChart*)GetDlgItem(IDC_CHART))->GetPrinter().BeginDoc();
((CTChart*)GetDlgItem(IDC_CHART))->GetPrinter().PrintPartial(width / 4, 0, width / 4 * 3, height / 256 * 9);
((CTChart*)GetDlgItem(IDC_CHART1))->GetPrinter().PrintPartial(width / 2, height / 32, width, height / 16);
m_chart.GetPrinter().EndDoc();
}
/*************************************************************************
*
* PreviewChart()
*
* 功 能: 预览图形
*
* 参 数: 无
*
* 返回值: 无
*
*************************************************************************/
void CCGraphDlg::PreviewChart()
{
m_chart.GetPrinter().ShowPreview();
}
/*************************************************************************
*
* SaveAsBitmap()
*
* 功 能: 保存为位图
*
* 参 数: CString strFileName
*
* 返回值: 无
*
*************************************************************************/
void CCGraphDlg::SaveAsBitmap(CString strFileName)
{
m_chart.GetExport().SaveToBitmapFile(strFileName);
}
BOOL CCGraphDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (m_hAccel != NULL)
if(TranslateAccelerator(this->m_hWnd, m_hAccel, pMsg))
return true;
return CDialog::PreTranslateMessage(pMsg);
}
void CCGraphDlg::OnDestroy()
{
CDialog::OnDestroy();
if (m_hAccel != NULL)
DestroyAcceleratorTable(m_hAccel);
// TODO: Add your message handler code here
}
void CCGraphDlg::OnContextMenu(CWnd*, CPoint point)
{
if(GetCapture())
return; // CG: This block was added by the Pop-up Menu component { if (point.x == -1 && point.y == -1){ //keystroke invocation CRect rect; GetClientRect(rect); ClientToScreen(rect); point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu;
VERIFY(menu.LoadMenu(IDR_POPUP_VENUS));
CMenu* pPopup = menu.GetSubMenu(3);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = AfxGetMainWnd();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -