www.pudn.com > wavelet-vc++6.rar > CS92.cpp
// CS92->cpp : implementation file
//
#include "stdafx.h"
#include "wavelet.h"
#include "CS92.h"
#include "MainFrm.h"
#include "waveletView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCS92 dialog
CCS92::CCS92(CWnd* pParent /*=NULL*/)
: CDialog(CCS92::IDD, pParent)
{
//{{AFX_DATA_INIT(CCS92)
m_filename = _T("");
m_datalength = 0;
//}}AFX_DATA_INIT
}
void CCS92::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCS92)
DDX_Text(pDX, IDC_EDIT1, m_filename);
DDX_Text(pDX, IDC_EDIT2, m_datalength);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCS92, CDialog)
//{{AFX_MSG_MAP(CCS92)
ON_BN_CLICKED(IDC_FILELOOK, OnFilelook)
ON_WM_SIZE()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCS92 message handlers
void CCS92::OnFilelook()
{
// TODO: Add your control notification handler code here
static char szFilter[]="DAT文件(*.dat)|*.dat||";
CFileDialog dlg(TRUE,"dat",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
if(dlg.DoModal()==IDOK)
{
m_filename=dlg.GetPathName();
}
UpdateData(FALSE);
}
void CCS92::DrawWave()
{
CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->GetMainWnd();
CWaveletView* pView=(CWaveletView*)pFrame->GetActiveView();
CDC* dc=pView->GetDC();
CFile file;
float* p;
if(!file.Open((LPCTSTR)m_filename,CFile::modeRead))
{
AfxMessageBox("打不开文件!");
return ;
}
p=new float[sizeof(float)*m_datalength];
if(file.Read(p,m_datalength*sizeof(float))!=m_datalength*sizeof(float))
{
AfxMessageBox("读文件出错.......!");
return;
}
file.Close();
if(m_filename==""||m_datalength==0)
return;
int k;
float max=0,min=1000,temp;
CPen pen(PS_SOLID,1,RGB(255,0,0));
CPen* oldpen;
oldpen=dc->SelectObject(&pen);
dc->MoveTo(65,400);dc->LineTo(577,400);
dc->LineTo(577,80);dc->LineTo(65,80);dc->LineTo(65,400);
dc->MoveTo(165,395);dc->LineTo(165,400);
dc->MoveTo(265,395);dc->LineTo(265,400);
dc->MoveTo(265,395);dc->LineTo(265,400);
dc->MoveTo(265,395);dc->LineTo(265,400);
dc->MoveTo(365,395);dc->LineTo(365,400);
dc->MoveTo(465,395);dc->LineTo(465,400);
dc->MoveTo(565,395);dc->LineTo(565,400);
dc->TextOut(137,25,m_filename);
dc->TextOut(137,405,"100");
dc->TextOut(237,405,"200");
dc->TextOut(337,405,"300");
dc->TextOut(437,405,"400");
dc->TextOut(537,405,"500");
dc->MoveTo(65,95);dc->LineTo(70,95);
dc->MoveTo(65,167);dc->LineTo(70,167);
dc->MoveTo(65,240);dc->LineTo(70,240);
dc->MoveTo(65,312);dc->LineTo(70,312);
dc->MoveTo(65,385);dc->LineTo(70,385);
dc->TextOut(13,92,"1.0");
dc->TextOut(13,163,"0.5");
dc->TextOut(10,237,"0.0");
dc->TextOut(1,308,"-0.5");
dc->TextOut(1,380,"-1.0");
for(k=0;kmax) max=*(p+k);
if(*(p+k)SelectObject(&pen1);
dc->MoveTo(65,int(240-*p*temp));
for(k=1;k<=m_datalength-1;k++)
dc->LineTo(65+k,int(240-*(p+k)*temp));
pen1.DeleteObject();
}
void CCS92::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
flag=TRUE;
}
void CCS92::OnPaint()
{
CPaintDC dc(this); // device context for painting
if(flag)
{
DrawWave();
flag=FALSE;
}
// Do not call CDialog::OnPaint() for painting messages
}