?? klineobject.cpp
字號:
// KLineObject.cpp : 實現文件
//
#include "stdafx.h"
#include "KLine.h"
#include "KLineObject.h"
#include ".\klineobject.h"
// CKLineObject
IMPLEMENT_DYNAMIC(CKLineObject, CWnd)
CKLineObject::CKLineObject()
: m_GraphFillType(0)
{
m_GraphDC = NULL;
m_GraphBitmap = NULL;
m_GradientDC = NULL;
m_GradientBitmap = NULL;
m_GraphGradientColor1 = RGB(0,0,64);
m_GraphGradientColor2 = RGB(0,0,216);
m_GraphFillType = GB_SOLID;
}
CKLineObject::~CKLineObject()
{
delete m_2DKLineGraph;
m_2DKLineGraph = NULL;
// Delete graph DC and bitmap
m_GraphDC->DeleteDC();
delete m_GraphDC;
m_GraphDC = NULL;
m_GraphBitmap->DeleteObject();
delete m_GraphBitmap;
m_GraphBitmap = NULL;
// Delete gradient DC and bitmap
m_GradientDC->DeleteDC();
delete m_GradientDC;
m_GradientDC = NULL;
m_GradientBitmap->DeleteObject();
delete m_GradientBitmap;
m_GradientBitmap = NULL;
}
BEGIN_MESSAGE_MAP(CKLineObject, CWnd)
ON_WM_PAINT()
// ON_WM_SIZE()
END_MESSAGE_MAP()
// CKLineObject 消息處理程序
BOOL CKLineObject::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
CRect rectGraph( rect);
m_Position = CPoint(rectGraph.left,rectGraph.top);
m_Size = CSize(rectGraph.right,rectGraph.bottom);
m_GraphBackgroundColor = RGB(0,0,0);
m_GraphRedLineColor = RGB(255,0,0);
m_GraphGreenLineColor = RGB(0,255,255);
return CWnd::Create(lpszClassName, lpszWindowName, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPSIBLINGS, rectGraph, pParentWnd, nID, pContext);
}
void CKLineObject::CreateGraph(int g_type)
{
switch(g_type)
{
case GT_2DKLINE:
m_2DKLineGraph = new C2DKLineGraph(m_Size);
break;
}
CDC* pDC = GetDC();
m_GraphDC = new CDC();
m_GraphDC->CreateCompatibleDC(pDC);
m_GraphBitmap = new CBitmap();
m_GraphBitmap->CreateCompatibleBitmap(pDC,m_Size.cx,m_Size.cy);
m_GraphDC->SelectObject(m_GraphBitmap);
m_GradientDC = new CDC();
m_GradientDC->CreateCompatibleDC(pDC);
m_GradientBitmap = new CBitmap();
m_GradientBitmap->CreateCompatibleBitmap(pDC,m_Size.cx,m_Size.cy);
m_GradientDC->SelectObject(m_GradientBitmap);
GRADIENT_RECT gRect;
TRIVERTEX gVert[2];
gVert[0].x = 0;
gVert[0].y = 0;
gVert[0].Red = (GetRValue(m_GraphGradientColor1)<<8);
gVert[0].Green = (GetGValue(m_GraphGradientColor1)<<8);
gVert[0].Blue = (GetBValue(m_GraphGradientColor1)<<8);
gVert[0].Alpha = 0x0000;
gVert[1].x = m_Size.cx;
gVert[1].y = m_Size.cy;
gVert[1].Red = (GetRValue(m_GraphGradientColor2)<<8);
gVert[1].Green = (GetGValue(m_GraphGradientColor2)<<8);
gVert[1].Blue = (GetBValue(m_GraphGradientColor2)<<8);
gVert[1].Alpha = 0x0000;
gRect.UpperLeft = 0;
gRect.LowerRight = 1;
GradientFill(m_GradientDC->m_hDC,gVert,2,&gRect,1,GRADIENT_FILL_RECT_V);
CWnd::ReleaseDC(pDC);
}
void CKLineObject::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC * pDC = GetDC();
CRect gRect;
this->GetClientRect(gRect);
CBrush bgBrush(m_GraphBackgroundColor);
pDC->SelectObject(bgBrush);
FillRect(pDC->m_hDC,&gRect,bgBrush);
//Begin BuildGraph
m_2DKLineGraph->SetGraphSize(CSize(gRect.Width(),gRect.Height()));
m_2DKLineGraph->CreateGraph(pDC);
//End BuildGraph
pDC->SelectObject(bgBrush);
CWnd::ReleaseDC(pDC);
}
void CKLineObject::SetGraphFillType(int g_fill)
{
switch(g_fill)
{
case GB_SOLID:
m_GraphFillType = GB_SOLID;
break;
case GB_GRADIENT:
m_GraphFillType = GB_GRADIENT;
break;
default:
m_GraphFillType = GB_SOLID;
break;
}
}
int CKLineObject::GetGraphFillType()
{
return m_GraphFillType;
}
void CKLineObject::SetC2DKLineGraphValue(__time64_t t, double startvalue, double maxvalue, double minvalue, double endvalue)
{
if (m_2DKLineGraph!=NULL)
{
m_2DKLineGraph->SetValue(t,startvalue,maxvalue,minvalue,endvalue);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -