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

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 workingon 的 blog

"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);

本文关键:我自己写的坐标图,可以定制坐标并切换,也可以用不同颜色画直线和曲线
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top