www.pudn.com > CamberCurveTest_2.rar > CamberCurveTest_2Dlg.cpp
// CamberCurveTest_2Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "CamberCurveTest_2.h"
#include "CamberCurveTest_2Dlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
# define Num 100
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCamberCurveTest_2Dlg dialog
CCamberCurveTest_2Dlg::CCamberCurveTest_2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CCamberCurveTest_2Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCamberCurveTest_2Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
Status = 0; //程序启动时,处于未画曲线的状态。
}
void CCamberCurveTest_2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCamberCurveTest_2Dlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCamberCurveTest_2Dlg, CDialog)
//{{AFX_MSG_MAP(CCamberCurveTest_2Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_DRAWCURVE, OnDrawcurve)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON1, OnStopDrawLine)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCamberCurveTest_2Dlg message handlers
BOOL CCamberCurveTest_2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CCamberCurveTest_2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCamberCurveTest_2Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCamberCurveTest_2Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCamberCurveTest_2Dlg::OnDrawcurve()
{
// TODO: Add your control notification handler code here
Status = 1; //开始画曲线。
CurveData[0]=0.0;
CurveData[1]=0.1;
CurveData[2]=0.5;
CurveData[3]=0.8;
CurveData[4]=0.9;
CurveData[5]=1.1;
CurveData[6]=1.3;
CurveData[7]=1.0;
CurveData[8]=0.7;
CurveData[9]=0.6;
CurveData[10]=0.6;
CurveData[11]=0.4;
CurveData[12]=0.3;
CurveData[13]=0.2;
CurveData[14]=0.5;
CurveData[15]=0.7;
CurveData[16]=0.8;
CurveData[17]=0.9;
CurveData[18]=1.0;
CurveData[19]=1.2;
CurveData[20]=1.5;
CurveData[21]=1.8;
CurveData[22]=1.6;
CurveData[23]=1.4;
CurveData[24]=1.3;
CurveData[25]=1.2;
CurveData[26]=1.4;
CurveData[27]=1.6;
CurveData[28]=1.8;
CurveData[29]=2.0;
CurveData[30]=2.2;
CurveData[31]=2.1;
CurveData[32]=2.3;
CurveData[33]=2.5;
CurveData[34]=2.6;
CurveData[35]=2.7;
CurveData[36]=2.8;
CurveData[37]=2.5;
CurveData[38]=2.4;
CurveData[39]=2.2;
CurveData[40]=2.1;
CurveData[41]=2.4;
CurveData[42]=2.8;
CurveData[43]=3.0;
CurveData[44]=3.2;
CurveData[45]=3.3;
CurveData[46]=3.4;
CurveData[47]=3.6;
CurveData[48]=3.8;
CurveData[49]=4.0;
CurveData[50]=4.1;
CurveData[51]=4.2;
CurveData[52]=4.3;
CurveData[53]=4.5;
CurveData[54]=4.6;
CurveData[55]=4.7;
CurveData[56]=5.0;
CurveData[57]=4.9;
CurveData[58]=4.8;
CurveData[59]=4.7;
CurveData[60]=4.6;
CurveData[61]=4.8;
CurveData[62]=4.4;
CurveData[63]=4.5;
CurveData[64]=4.3;
CurveData[65]=4.2;
CurveData[66]=4.1;
CurveData[67]=4.0;
CurveData[68]=3.8;
CurveData[69]=3.6;
CurveData[70]=3.4;
CurveData[71]=3.2;
CurveData[72]=3.0;
CurveData[73]=2.8;
CurveData[74]=2.6;
CurveData[75]=2.7;
CurveData[76]=2.5;
CurveData[77]=2.4;
CurveData[78]=2.3;
CurveData[79]=2.2;
SetTimer(1, 500, 0);
CWnd* pWnd=GetDlgItem(IDC_EDIT_CAMBERSHOW);
CDC* pDC=pWnd->GetDC();
//pWnd->Invalidate();
//pWnd->UpdateWindow();
CRect rcRect;
pWnd->GetClientRect(rcRect);
CPen pen1(PS_SOLID,0,RGB(255,0,0)); //选择画笔
CPen *oldpen1=NULL;
oldpen1=pDC->SelectObject(&pen1);
int Width;
Width=rcRect.Width();
int Height;
Height=rcRect.Height();
// p_y = new float[Width];
// srand( (unsigned)time( NULL ) );
// for(int i = 0; i < Width; i ++)
// {
// p_y[i] = (rand() % 11);
// }
xunit=Width/80;
yunit=Height/120;
xorigin=rcRect.left;
yorigin=rcRect.bottom;
CPen pen2(PS_SOLID,0,RGB(0,0,0)); //选择画笔
oldpen1=pDC->SelectObject(&pen2);
pDC->MoveTo(0,0);
pDC->LineTo(rcRect.left,Height);
pDC->MoveTo(rcRect.right,yorigin/2);
pDC->LineTo(rcRect.left,rcRect.bottom/2);
//pDC->TextOut(2,(rcRect.bottom/2 + 2),"(0,0)");
CString str_h; //水平标尺字符格式
CString str_v; //垂直标尺字符格式
for(int i = 0; i <= 8; i ++)
{
str_h.Format("%d",10*i);
if(i == 8)
{
pDC->TextOut((Width/8)*i-10,(rcRect.bottom/2 + 2),str_h); //画水平标尺
}
else if(i == 0)
{
//此时不写该坐标
}
else
{
pDC->TextOut((Width/8)*i-10,(rcRect.bottom/2 + 2),str_h); //画水平标尺
}
}
for(i = 0; i <= 4; i ++)
{
str_v.Format("%0.1f",0.2-i*0.1);
if(i == 4)
{
pDC->TextOut(6,0+(rcRect.bottom/4)*i - 16 ,str_v); //画垂直标尺
}
else if(i == 2)
{
pDC->TextOut(6,0+(rcRect.bottom/4)*i+2,str_v); //画垂直标尺
}
else
{
pDC->TextOut(6,0+(rcRect.bottom/4)*i,str_v); //画垂直标尺
}
}
//画水平刻度
for(i=0; i<=8;i++)
{
pDC->MoveTo((Width/8)*i,rcRect.bottom/2);
pDC->LineTo((Width/8)*i,rcRect.bottom/2 - 5);
}
//画垂直刻度
for(i=0;i<=4;i++)
{
pDC->MoveTo(0,0+(rcRect.bottom/4)*i);
pDC->LineTo(5,0+(rcRect.bottom/4)*i);
}
//x_last = rcRect.right; //与编辑框的最后的边缘点相连,20070317注释掉
//y_last = rcRect.bottom/2; //与编辑框的最后的边缘点相连,20070317注释掉
//pDC->LineTo(x,y);
//pDC->MoveTo(x,y);
oldpen1=pDC->SelectObject(&pen1);
//BOOL tag = LineDDA(0,yorigin/2,Width,yorigin/2,(LINEDDAPROC)Proc,(LPARAM)pDC);
pDC->SelectObject(oldpen1);
pWnd->ReleaseDC(pDC);
}
void CCamberCurveTest_2Dlg::OnOK()
{
// TODO: Add extra validation here
//KillTimer(1);
CDialog::OnOK();
}
void CALLBACK Proc(int X,int Y,LPARAM lpData)
{
// CDC *pDC;
// pDC = (CDC *)lpData;
//pDC->SetPixel(X,Y+100*sin(3.1415926*X/144),RGB(0,0,0));
//pDC->SetPixel(X,Y+p_y[X],RGB(0,0,0));
}
void CCamberCurveTest_2Dlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
int x,y;
static int counter = 0;
CWnd* pWnd=GetDlgItem(IDC_EDIT_CAMBERSHOW);
CDC* pDC=pWnd->GetDC();
pDC->MoveTo(x_last,y_last);
x=xorigin+counter*xunit;
y=yorigin/2 - (int(CurveData[counter]*10))*yunit;
pDC->LineTo(x,y);
//pDC->MoveTo(x,y);
x_last = x;
y_last = y;
counter ++;
CDialog::OnTimer(nIDEvent);
}
void CCamberCurveTest_2Dlg::OnStopDrawLine()
{
// TODO: Add your control notification handler code here
Status = 0; //停止画曲线。
KillTimer(1);
}