⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waveshowerview.cpp

📁 一个将MIT/BH心电图数据库中的数据转换成INTEL格式文件并显示出来的程序
💻 CPP
字号:
// WaveShowerView.cpp : implementation of the CWaveShowerView class
//

#include "stdafx.h"
#include "WaveShower.h"

#include "WaveShowerDoc.h"
#include "WaveShowerView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CWaveShowerView

IMPLEMENT_DYNCREATE(CWaveShowerView, CFormView)

BEGIN_MESSAGE_MAP(CWaveShowerView, CFormView)
	//{{AFX_MSG_MAP(CWaveShowerView)
	ON_COMMAND(IDM_OPENDATA, OnOpendata)
	ON_WM_TIMER()
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWaveShowerView construction/destruction

CWaveShowerView::CWaveShowerView()
	: CFormView(CWaveShowerView::IDD)
{
	//{{AFX_DATA_INIT(CWaveShowerView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here
    m_dx=0;
	m_IsPause=FALSE;
}

CWaveShowerView::~CWaveShowerView()
{
	delete[] value;
   // KillTimer(0);
  //  KillTimer(1);
}

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

BOOL CWaveShowerView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CWaveShowerView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
    GetScreenRect();
	for(int i=0;i<m_DX;i++)
		value[i].x=value[i].y=0;
	SetTimer(0,10,NULL);

}

/////////////////////////////////////////////////////////////////////////////
// CWaveShowerView diagnostics

#ifdef _DEBUG
void CWaveShowerView::AssertValid() const
{
	CFormView::AssertValid();
}

void CWaveShowerView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CWaveShowerDoc* CWaveShowerView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWaveShowerDoc)));
	return (CWaveShowerDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CWaveShowerView message handlers

void CWaveShowerView::OnOpendata() 
{
	// TODO: Add your command handler code here
	CString FileName="";
	CFile file;
	CFileDialog dlg(TRUE,"*","*.*",
		OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"所有文件(*.*)|*.*||",NULL);
	if(dlg.DoModal()==IDOK)
	{
		KillTimer(1);
		FileName=dlg.GetPathName();
		file.Open(FileName,CFile::modeReadWrite);
		m_BufLen=file.GetLength();
		buffer= new unsigned char[m_BufLen+m_DX+10];
		file.Read(buffer,m_BufLen);
		file.Close();
		SetTimer(1,10,NULL);
	}

}

void CWaveShowerView::GetScreenRect()
{
	CWnd* pStatic = GetDlgItem(IDC_SCREEN);
	pStatic->GetWindowRect(&rect);
	ScreenToClient(&rect);
	rect.top+=4;
	rect.left+=4;
	rect.bottom-=4;
	rect.right-=4;
	m_Y0=(rect.bottom-rect.top)/2+rect.top;
	m_DX=rect.Width();
	m_DY=rect.Height()/2;
	value=new CPoint[m_DX];


}

void CWaveShowerView::CleanScreen()
{
	CDC* pDC=GetDC();
	CPen pen1(PS_SOLID,1,RGB(255,255,255));
	CPen* oldPen1=pDC->SelectObject(&pen1);
	for(int i=rect.top;i<rect.bottom;i++)
	{
		pDC->MoveTo(rect.left,i);
		pDC->LineTo(rect.right,i);
	}
	pDC->SelectObject(&oldPen1);
	CPen pen2(PS_SOLID,1,RGB(0,0,0));
	CPen* oldPen2=pDC->SelectObject(&pen2);
	pDC->MoveTo(rect.left,m_Y0);
//	pDC->LineTo(rect.right,m_Y0);
	pDC->SelectObject(&oldPen2);
	ReleaseDC(pDC);

}

void CWaveShowerView::DrawPoint(CPoint pt, COLORREF color)
{
	CDC* pDC=GetDC();
	pDC->SetPixel(rect.left+pt.x,m_Y0-pt.y,color);
	ReleaseDC(pDC);


}

void CWaveShowerView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	WORD tmpval;
/*	//代码一:有闪烁的代码
	if(nIDEvent==0)
	{
		CleanScreen();
		for(int i=0;i<m_DX;i++)
			DrawPoint(value[i],RGB(0,255,0));
	}
	if(nIDEvent==1)
	{
		m_dx+=2;
		for(int i=0;i<m_DX;i++)
		{
			value[i].x=i;
			if(m_dx+i<0)
				buffer[m_dx+i]=128;
			if(m_dx+i<-m_DX)
				m_dx-=2;
			if(m_dx+i>m_BufLen)
				buffer[m_dx+i]=128;
			if(m_dx+i>m_BufLen+m_DX)
				m_dx-=2;
			value[i].y=m_DY*(buffer[m_dx+i]-128)/256;
		}
	}*/
	if(nIDEvent==0)
	{
		CDC* pDC=GetDC();
		CDC dc; 
		CBitmap bitmap; 
		CBitmap* pOldBitmap; 
		CRect client; 
		pDC->GetClipBox(client); //检取无效区 
		//创建一个与pDC兼容的内存设备环境 
		if(dc.CreateCompatibleDC(pDC)) 
		{ 
			//创建一与pDC兼容的位图,大小为整个客户区 
			if(bitmap.CreateCompatibleBitmap(pDC,rect.Width(), rect.Height()))
			{ 
				//使dc与pDC具有同样的映射关系 
				OnPrepareDC(&dc,NULL); 
				//将位图选入内存环境
				pOldBitmap=dc.SelectObject(&bitmap); 
				//使dc的整个客户区都成无效区 
				dc.SelectClipRgn(NULL); 
				//再“与上”检取的无效区,使内存环境与
				//pDC检取的无效区相等 
				dc.IntersectClipRect(client); 
			} 
		} 
		CleanScreen();
		for(int i=0;i<m_DX;i++)
			DrawPoint(value[i],RGB(0,0,0));
		dc.SelectObject(pOldBitmap); 
		ReleaseDC(pDC); 
	}
	if(nIDEvent==1)
	{
		if(m_IsPause==FALSE)
		{
		m_dx+=2;
		for(int i=0;i<m_DX;i++)
		{
			value[i].x=i;
			if(m_dx+i<0)
			{
			   buffer[m_dx+2*i+1]=0x00;
			   buffer[m_dx+2*i]=0x04;
			}

				
			if(m_dx+i<-m_DX)
				m_dx-=2;
			if(m_dx+i>m_BufLen)
			{
			   buffer[m_dx+2*i+1]=0x00;
			   buffer[m_dx+2*i]=0x04;
			}
			
			if(m_dx+i>m_BufLen+m_DX)
				m_dx-=2;
		    tmpval=MAKEWORD(buffer[m_dx+2*i+1],buffer[m_dx+2*i]);
			value[i].y=4*m_DY*(tmpval-1024)/2048;
			
		}
		}
		else
		{
for(int i=0;i<m_DX;i++)
		{
			value[i].x=i;
			if(m_dx+i<0)
			{
			   buffer[m_dx+2*i+1]=0x00;
			   buffer[m_dx+2*i]=0x04;
			}

				
			if(m_dx+i<-m_DX)
				m_dx-=2;
			if(m_dx+i>m_BufLen)
			{
			   buffer[m_dx+2*i+1]=0x00;
			   buffer[m_dx+2*i]=0x04;
			}
			
			if(m_dx+i>m_BufLen+m_DX)
				m_dx-=2;
		    tmpval=MAKEWORD(buffer[m_dx+2*i+1],buffer[m_dx+2*i]);
			value[i].y=4*m_DY*(tmpval-1024)/2048;
			
		}
		}
		
	}


	CFormView::OnTimer(nIDEvent);
}

void CWaveShowerView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_IsPause=~m_IsPause;
	CFormView::OnLButtonDown(nFlags, point);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -