分享
 
 
 

我自己写的坐标图,可以定制坐标并切换,也可以用不同颜色画直线和曲线

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

"CGraph.h"

#if !defined(AFX_GRAPH_H__F235CDCF_7878_44AB_9A72_DDB5384D32BF__INCLUDED_)

#define AFX_GRAPH_H__F235CDCF_7878_44AB_9A72_DDB5384D32BF__INCLUDED_

#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

// Graph.h : header file

//Create by yangyihong,contact:yang_yi_hong@yahoo.com.cn

/////////////////////////////////////////////////////////////////////////////

// CGraph window

typedef struct tagGraphStr {

char title[20];//标题

char xstr[20];//横坐标名称

char ystr[20];//纵坐标名称

double dORGX,dMAXX;//横坐标原点,最大值

double dORGY,dMAXY;//纵坐标原点,最大值

}GSTR;

static GSTR gstr[]={

{"硅光电池","波长(nm)","光谱响应度(A/W)",380,600,0,4},

{"光电二极管","波长(nm)","光谱响应度(A/W)",380,600,0,4},

{"光电三极管","波长(nm)","光谱响应度(A/W)",380,600,0,4},

{"光敏电阻","波长(nm)","光谱响应度(A/W)",380,600,0,4},

{"PMT阴极特性","电压(V)","电流(nA)",0,12,0,5},

{"PMT阳极特性","电压(V)","电流(nA)",0,12,0,5},

{"PMT放大倍数","电压","放大倍数",0,12,0,5},

{"APD特性","电压(V)","电流(nA)",0,12,0,500}

};

class CGraph : public CWnd

{

// Construction

public:

CGraph();

// Attributes

public:

double m_dORGX , m_dORGY ;

double m_dMAXX , m_dMAXY ;

double m_dDIVX , m_dDIVY ;//横坐标和纵坐标分度

// Operations

public:

// Overrides

// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(CGraph)

public:

virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);

//}}AFX_VIRTUAL

// Implementation

public:

void SwitchGraph(int index);//切换坐标

void DrawLine (double X1,double Y1,double X2,double Y2,COLORREF cr);//画线

void DrawPoint(double X,double Y);//画点

void SetXScale(double dOrgX,double dMaxX);//设定X坐标分度

void SetYScale(double dOrgY, double dMaxY);//设定Y坐标分度

void SetTitle(int nIndex);//设定标题

virtual ~CGraph();

// Generated message map functions

protected:

//{{AFX_MSG(CGraph)

afx_msg void OnPaint();

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

private:

GSTR *m_pGstr;

void OnDraw ();

};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_GRAPH_H__F235CDCF_7878_44AB_9A72_DDB5384D32BF__INCLUDED_)

"CGraph.c"

// Graph.cpp : implementation file

//2005/4/20

//Create by yangyihong,contact:yang_yi_hong@yahoo.com.cn

#include "stdafx.h"

#include "CSY.h"

#include "Graph.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

#define ORGX 65

#define ORGY 430

#define MAXX 550

#define MAXY 400//坐标在窗口上的位置

#define nX 100//X分度数

#define nY 100//Y分度数

/////////////////////////////////////////////////////////////////////////////

// CGraph

CGraph::CGraph()

{

SetTitle(0);

SetXScale(380,1000);

SetYScale(0,10);

}

CGraph::~CGraph()

{

}

BEGIN_MESSAGE_MAP(CGraph, CWnd)

//{{AFX_MSG_MAP(CGraph)

ON_WM_PAINT()

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// CGraph message handlers

void CGraph::OnDraw()

{

int i;

int nORGX,nORGY,nMAXX,nMAXY;

CRect rc;

GetClientRect(&rc);

CDC *pDC=GetDC();

pDC->SetBkMode(TRANSPARENT);

pDC->SetMapMode(MM_ANISOTROPIC);

pDC->SetWindowExt(640, 480);

pDC->SetViewportExt(rc.right, rc.bottom);

nORGX = ORGX, nORGY = ORGY;

nMAXX = MAXX, nMAXY = MAXY;

CFont fnt;

CFont *poldfnt;

LOGFONT logFont;

memset(&logFont,0,sizeof(LOGFONT));

logFont.lfHeight=12;logFont.lfWidth = 10;

if( fnt.CreateFontIndirect(&logFont))

poldfnt = pDC->SelectObject(&fnt);

// 显示背景虚线

CPen newPen(PS_DOT, 1, RGB(0, 0, 0));

CPen* pOldPen = pDC->SelectObject(&newPen);

for( i = 0; i < nY/10; i++)

{

CString str;

str.Format("%3.1f",m_dORGY+i*m_dDIVY*10);

pDC->MoveTo(nORGX, nORGY - i*nMAXY/10);

pDC->LineTo(nORGX + nMAXX, nORGY - i*nMAXY/10);

pDC->TextOut(nORGX-50, nORGY - i*nMAXY/10-4,str);

for (int j=0;j<10;j++){

CPen newPen(PS_SOLID, 1, RGB(0, 0, 0));

CPen* pOldPen = pDC->SelectObject(&newPen);

pDC->MoveTo(nORGX,nORGY - i*nMAXY/10-j*nMAXY/nY);

if(j==5) {

pDC->LineTo(nORGX+4+4,nORGY - i*nMAXY/10-j*nMAXY/nY);

}else{

pDC->LineTo(nORGX+4,nORGY - i*nMAXY/10-j*nMAXY/nY);

}

pDC->SelectObject(pOldPen);

}

}

CString str;str.Format("%3.1f",i*m_dDIVY*10);

pDC->TextOut(nORGX-50, nORGY - i*nMAXY/10-4,str);

for(i = 0; i < nX/10; i++)

{

CString str;

str.Format("%3.1f",m_dORGX+i*m_dDIVX*10);

pDC->MoveTo(nORGX + i*nMAXX/10, nORGY);

pDC->LineTo(nORGX + i*nMAXX/10, nORGY - nMAXY);

pDC->TextOut(nORGX + i*nMAXX/10-8, nORGY+4,str);

for (int j=0;j<10;j++){

CPen newPen(PS_SOLID, 1, RGB(0, 0, 0));

CPen* pOldPen = pDC->SelectObject(&newPen);

pDC->MoveTo(nORGX + i*nMAXX/10+j*nMAXX/100,nORGY);

if(j==5){

pDC->LineTo(nORGX + i*nMAXX/10+j*nMAXX/nX,nORGY - 3 -3);

}else{

pDC->LineTo(nORGX + i*nMAXX/10+j*nMAXX/nX,nORGY - 3);

}

pDC->SelectObject(pOldPen);

}

}

str.Format("%3.1f",m_dORGX+i*m_dDIVX*10);

pDC->TextOut(nORGX + i*nMAXX/10-8, nORGY+4,str);

pDC->SelectObject(pOldPen);

pDC->MoveTo(nORGX, nORGY);

pDC->LineTo(nORGX, nORGY - nMAXY);

pDC->MoveTo(nORGX + nMAXX, nORGY);

pDC->LineTo(nORGX + nMAXX, nORGY - nMAXY);

pDC->MoveTo(nORGX, nORGY);

pDC->LineTo(nORGX + nMAXX, nORGY);

pDC->MoveTo(nORGX, nORGY - nMAXY);

pDC->LineTo(nORGX + nMAXX, nORGY - nMAXY);

pDC->TextOut(nORGX+nMAXX/2-10,nORGY+20,m_pGstr->title);

pDC->TextOut(nORGX-10,nORGY-nMAXY-20,m_pGstr->ystr);

pDC->TextOut(nORGX+nMAXX-60,nORGY+20,m_pGstr->xstr);

if(poldfnt!=NULL)

pDC->SelectObject(poldfnt);

}

void CGraph::OnPaint()

{

CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here

OnDraw ();

// Do not call CWnd::OnPaint() for painting messages

}

BOOL CGraph::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)

{

return CWnd::Create(AfxRegisterWndClass(CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, NULL, (HBRUSH)(COLOR_BTNFACE+1),NULL),

NULL,

dwStyle,

rect,

pParentWnd,

nID,

pContext);

}

void CGraph::SetTitle(int nIndex)

{

m_pGstr= &gstr[nIndex];

}

void CGraph::SetXScale(double dOrgX, double dMaxX)

{

m_dMAXX = dMaxX;

m_dORGX = dOrgX;

m_dDIVX = m_dMAXX / nX;

}

void CGraph::SetYScale(double dOrgY, double dMaxY)

{

m_dMAXY = dMaxY;

m_dORGY = dOrgY;

m_dDIVY = m_dMAXY / nY;

}

void CGraph::DrawPoint(double X, double Y)

{

CRect rc;

GetClientRect(&rc);

CDC *pDC=GetDC();

pDC->SetMapMode(MM_ANISOTROPIC);

pDC->SetWindowExt(640, 480);

pDC->SetViewportExt(rc.right, rc.bottom);

int tmpX,tmpY;

tmpX = (int) (( X-m_dORGX) * MAXX/m_dMAXX + ORGX );

tmpY = (int) ( ORGY-(Y-m_dORGY) * MAXY/m_dMAXY );

pDC->MoveTo(tmpX-5,tmpY-5);

pDC->SetPixel(tmpX,tmpY,RGB(255,0,0));

}

void CGraph::DrawLine(double X1, double Y1, double X2, double Y2,COLORREF cr)

{

CRect rc;

GetClientRect(&rc);

CDC *pDC=GetDC();

pDC->SetMapMode(MM_ANISOTROPIC);

pDC->SetWindowExt(640, 480);

pDC->SetViewportExt(rc.right, rc.bottom);

int tmpX1,tmpY1,tmpX2,tmpY2;

tmpX1 = (int) (( X1-m_dORGX) * MAXX/m_dMAXX + ORGX );

tmpY1 = (int) ( ORGY-(Y1-m_dORGY) * MAXY/m_dMAXY );

tmpX2 = (int) (( X2-m_dORGX) * MAXX/m_dMAXX + ORGX );

tmpY2 = (int) ( ORGY-(Y2-m_dORGY) * MAXY/m_dMAXY );

CPen pn(PS_SOLID, 3, cr);

CPen *poldpn;

poldpn = pDC->SelectObject(&pn);

pDC->MoveTo(tmpX1,tmpY1);

pDC->LineTo(tmpX2,tmpY2);

pDC->SelectObject(poldpn);

}

void CGraph::SwitchGraph(int index)

{

if (index>=sizeof(gstr)){

DBG("下标超界");return;

}

SetTitle(index);

SetXScale(m_pGstr->dORGX,m_pGstr->dMAXX);

SetYScale(m_pGstr->dORGY,m_pGstr->dMAXY);

CRect rc;

GetClientRect(rc);

InvalidateRect(rc);

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有