?? recordcurse.cpp
字號:
// RecordCurse.cpp : implementation file
//
#include "stdafx.h"
#include "CSpeed.h"
#include "RecordCurse.h"
#include "mmTimers.h"
#define SHOW_X0 770
#define SHOW_X 930
#define SHOW_Y1 30
#define SHOW_Y2 60
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// RecordCurse dialog
RecordCurse::RecordCurse(CWnd* pParent /*=NULL*/)
: CDialog(RecordCurse::IDD, pParent)
{
//{{AFX_DATA_INIT(RecordCurse)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void RecordCurse::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(RecordCurse)
DDX_Control(pDX, IDC_SLIDER1, m_horscro);
DDX_Control(pDX, IDC_DRAW, m_Canvas);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(RecordCurse, CDialog)
//{{AFX_MSG_MAP(RecordCurse)
ON_BN_CLICKED(IDC_SELECT_RECORD, OnSelectRecord)
ON_WM_DESTROY()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// RecordCurse message handlers
int total_t=0;
void RecordCurse::OnSelectRecord()
{
// TODO: Add your control notification handler code here
char datfilepath[180];
CString ttt;
ttt.Format("%s\\data",exepath);
strcpy(datfilepath,ttt);
int point_size, point_num;
point_size = sizeof(SAMPLEPARAM);
CFileDialog dlg(true,NULL,NULL,OFN_OVERWRITEPROMPT,"數(shù)據(jù)文件(*.ddx)|*.ddx|全部文件(*.*)|*.*||",NULL);
dlg.m_ofn.lpstrInitialDir=datfilepath;
if(dlg.DoModal()==IDOK)
{
xfname=dlg.GetPathName();
start_pos = 0;
CFile DDXFile;
if(DDXFile.Open(xfname,CFile::modeRead|CFile::shareDenyNone))
{
point_num=DDXFile.GetLength()/point_size;
if(point_num<1)
{
havedata = FALSE;
DDXFile.Close();
MessageBox ("can't creat file");
return;
}
DDXFile.Seek(-point_size,CFile::end);
DDXFile.Read(&mypoint,point_size);
all_pos = int(total_t)+1;
}
else
all_pos = 0;
DDXFile.Close();
//
start_pos = 0;
havedata = TRUE;
havedata = GetData(start_pos);
}
}
void RecordCurse::OnDestroy()
{
KillTimer(1);
// stopTimer();
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
void RecordCurse::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
}
BOOL RecordCurse::OnInitDialog()
{
CDialog::OnInitDialog();
zero = 40;
startx = 4;
iscontinue = FALSE;
havedata = FALSE;
////////////初始化dcmemory/////////////////////
m_Canvas.GetClientRect(&WRect);
draw_size_x = WRect.Width()-startx-50;
draw_size_y = WRect.Height()-zero-2;
InitDrawItem();
SetDrawItem();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void RecordCurse::InitDrawItem()
{
draw_size_t = 600;
}
void RecordCurse::SetDrawItem()
{
double yy;
yy = (draw_size_y)*1.0;
int AllColor;
AllColor=RGB(255,0,0);
CString AllText;
AllText="(V) ";
mydraw.text=AllText;
mydraw.color=AllColor;//0;
mydraw.xs=yy/mypoint.speed_meas_t;
mydraw.max=mypoint.speed_meas_t;
}
BOOL RecordCurse::GetData(double now_pos)
{
if(!havedata)
return FALSE;
BOOL returndata;
returndata = FALSE;
CDC *pDC; //屏幕繪圖設(shè)備
pDC=m_Canvas.GetDC(); //獲得設(shè)備環(huán)境指針
CPen pen(PS_SOLID,1,RGB(0,0,255));
CPen *oldpen;
oldpen=pDC->SelectObject(&pen);
pDC->FillSolidRect(1,1,WRect.Width()-1,WRect.Height()-1,RGB(255,255,255));
pDC->SelectObject(oldpen);//恢復(fù)原來畫筆
pen.Detach();//將畫筆對象與其構(gòu)造的內(nèi)容分離,以便能再次構(gòu)造
double dx;
dx = (WRect.Width()-2-startx)*1.0/draw_size_t;
CFile DDXFile;
if(DDXFile.Open(xfname,CFile::modeRead|CFile::shareDenyNone))
{
int point_size, i;
point_size = sizeof(SAMPLEPARAM);
int point_num;
point_num=DDXFile.GetLength()/point_size;
if(point_num<1)
{
DDXFile.Close();
MessageBox("no data!");
returndata = FALSE;
}
else
{
DDXFile.Seek(-point_size,CFile::end);
DDXFile.Read(&mypoint,point_size);
all_pos = int(total_t)+1;
if(now_pos>all_pos-1)
now_pos = all_pos-1;
DrawGrid(pDC);
int i00;
pen.CreatePen(PS_SOLID,1,RGB(0,0,255));
pDC->SelectObject(&pen);
DDXFile.Seek(0,CFile::begin);
int pointx, pointy;
i00=0;
for(i=0;i<point_num;i++)
{
DDXFile.Read(&mypoint,point_size);
if(mypoint.speed_meas_t>=now_pos)//繪圖起點
{
mystartpoint = mypoint;
i00=i;
break;
}
}
BOOL isfirst;
isfirst = TRUE;
for(i=i00;i<point_num;i++)
{
DDXFile.Read(&mypoint,point_size);
if(mypoint.speed_meas_t-now_pos>=draw_size_t)
break;
pointx = startx+int((mypoint.speed_meas_t-now_pos)*dx);
pointy = int(WRect.Height()-zero);
if(pointy<1)
isfirst=TRUE;
if(i==i00||isfirst)
{
pDC->MoveTo(pointx, pointy);
}
else
{
pDC->LineTo(pointx, pointy);
}
if(pointy>1)
isfirst=FALSE;
}
pDC->SelectObject(oldpen);
pen.Detach();
returndata = TRUE;
DDXFile.Close();
}
}
pDC->SelectObject(oldpen);
pen.DeleteObject();
ReleaseDC(pDC);
if(returndata)
DisplayData();
return returndata;
}
void RecordCurse::DisplayData()
{
CString Result,m_str;
CDC *pDC=GetDC();
CFont myFont1;
CFont *pFont=GetFont();
LOGFONT lf;
if(pFont!=NULL)
pFont->GetObject(sizeof(LOGFONT),&lf);
else
::GetObject(GetStockObject(SYSTEM_FONT),sizeof(LOGFONT),&lf);
lf.lfHeight=15;
lf.lfWidth=8;
int len_2ch, show_x2;
len_2ch = 2*lf.lfWidth;
show_x2 = SHOW_X+len_2ch;
myFont1.CreateFontIndirect(&lf);
CFont *PreFont=pDC->SelectObject(&myFont1);
pDC->SetBkColor(GetSysColor(COLOR_BTNFACE));//設(shè)置背景顏色
pDC->SetTextColor(RGB(0,0,0));//設(shè)置字體顏色
/*
ftoat(mystartpoint.t);
char dis[15], dism[3],dish[4],diss[3];
CString Re1,Re2,Re3;
ftoat1(hour,3,dish,FALSE);//dis=string
ftoat1(minute,2,dism,FALSE);//dis=string
ftoat1(second,2,diss,FALSE);//dis=string
Re1=dish;
Re2=dism;
Re3=diss;
*/
// Result.Format("%s:%s:%s",Re1,Re2,Re3);
char dis[15];
pDC->TextOut(SHOW_X,SHOW_Y1,char(mypoint.speed_meas_t));//時間
ftoa(mystartpoint.speed_meas_t,5,3,dis,FALSE);
Result = dis;
pDC->TextOut(SHOW_X,SHOW_Y2, char(mypoint.speed_meas_t));//"電壓( V ):"
pDC->SelectObject(PreFont);
myFont1.DeleteObject();
ReleaseDC(pDC);
}
void RecordCurse::DrawGrid(CDC *pDC)
{
int pointx0, pointy;
pointx0 = startx;
pointy = int(WRect.Height()-zero);
int yy;
yy=draw_size_y;
double dx, dy;
dx = (draw_size_x)*1.0/draw_size_t;
CString str;
int i , j, k, m;
int pointx;
//t軸坐標(biāo)
int t_100,all_100;
t_100 = int(start_pos/100);
all_100 = draw_size_t/100+1;
pointx = int(pointx0-dx*(start_pos-t_100*100));
pDC->SetTextColor(RGB(155,200,200));
//zero
CPen newPen1,newPen2;
CPen *oldpen;
newPen1.CreatePen(PS_DASH,2,RGB(155,200,200));
newPen2.CreatePen(PS_DASH,1,RGB(155,200,200));
oldpen=pDC->SelectObject(&newPen1);
pDC->MoveTo(1,pointy);
pDC->LineTo(WRect.Width()-1,pointy);
//左邊縱坐標(biāo)
pDC->MoveTo(startx, pointy-yy);
pDC->LineTo(startx,pointy);
pDC->MoveTo(1,pointy-yy);
pDC->LineTo(WRect.Width()-1,pointy-yy);
oldpen=pDC->SelectObject(&newPen2);
j=0;
for( j=0; j<t_100+all_100; j++)
{
for(i=0;i<5;i++)
{
k=int(pointx+dx*100*j);
m=int(pointx+dx*(100*j+i*20));
if(i==0)
{
if(k>=startx && k<=WRect.Width()-2)
{
if(k<WRect.Width()-30)
{
int data_t;
data_t = int(t_100*100+100*j);
str.Format("%d",data_t);
pDC->TextOut(k,pointy+15, str);
}
pDC->MoveTo(k,pointy-yy);
pDC->LineTo(k,pointy+20);
}
}
else
{
if(m>=startx && m<=WRect.Width()-2)
{
pDC->MoveTo(m,pointy);
pDC->LineTo(m,pointy+10);
}
}
}
}
dy = 1.0*(draw_size_y)/100;
oldpen=pDC->SelectObject(&newPen2);
pDC->MoveTo(startx, int(pointy-dy*(20+4)));
pDC->LineTo(WRect.Width()-1, int(pointy-dy*(20+4)));
pDC->SelectObject(oldpen);
newPen1.DeleteObject();
newPen2.DeleteObject();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -