www.pudn.com > ImgFFT.zip > StatChart.cpp


// StatChart.cpp : implementation file
//

#include "stdafx.h"
#include "Pro2.h"
#include "StatChart.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CStatChart dialog


CStatChart::CStatChart(CWnd* pParent /*=NULL*/)
: CDialog(CStatChart::IDD, pParent)
{
//{{AFX_DATA_INIT(CStatChart)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}


void CStatChart::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStatChart)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStatChart, CDialog)
//{{AFX_MSG_MAP(CStatChart)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStatChart message handlers

void CStatChart::OnPaint()
{
CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here

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

//get the tag
CWnd* pWnd=GetDlgItem(IDC_CHART);

CDC* pDC=pWnd->GetDC();
pWnd->Invalidate();
pWnd->UpdateWindow();

pDC->Rectangle(0,0,330,300);

//create a pain object
CPen* pPenRed=new CPen;

pPenRed->CreatePen(PS_SOLID,1,RGB(255,0,0));

CPen* pOldPen=pDC->SelectObject(pPenRed);

pDC->MoveTo(10,10);

pDC->LineTo(10,280);

pDC->LineTo(320,280);

//paint the scale of X direction
CString strTemp;
strTemp.Format("0");
pDC->TextOut(10,283,strTemp);
strTemp.Format("50");
pDC->TextOut(60,283,strTemp);
strTemp.Format("100");
pDC->TextOut(110,283,strTemp);
strTemp.Format("150");
pDC->TextOut(160,283,strTemp);
strTemp.Format("200");
pDC->TextOut(210,283,strTemp);
strTemp.Format("255");
pDC->TextOut(265,283,strTemp);

for(int i=0;i<256;i+=5)
{
if((i&amt;1)==0)
{
pDC->MoveTo(i+10,280);
pDC->LineTo(i+10,284);
}
else
{
pDC->MoveTo(i+10,280);
pDC->LineTo(i+10,282);
}
}

pDC->MoveTo(315,275);
pDC->LineTo(320,280);
pDC->LineTo(315,285);

pDC->MoveTo(10,10);
pDC->LineTo(5,15);
pDC->MoveTo(10,10);
pDC->LineTo(15,15);

LONG lMaxCount=0;

//get the maximum number
for(i=0;i<=255;i++)
{
if(m_nStat[i]>lMaxCount)
lMaxCount=m_nStat[i];
}

pDC->MoveTo(10,25);
pDC->LineTo(14,25);
strTemp.Format(">d",lMaxCount);
pDC->TextOut(11,26,strTemp);

CPen* pPenBlue=new CPen;
pPenBlue->CreatePen(PS_SOLID,1,RGB(0,0,255));

pDC->SelectObject(pPenBlue);

if(lMaxCount>0)
{
for(i=0;i<=255;i++)
{
pDC->MoveTo(i+10,280);
pDC->LineTo(i+10,281-(int)(m_nStat[i]*256/lMaxCount));
}
}

pDC->SelectObject(pOldPen);

delete pPenRed;
delete pPenBlue;
}

BOOL CStatChart::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here


return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}