#include "stdafx.h"
#include "MyView.h"
#include "DemoVCDlg.h"

CMyView::CMyView()
{
	m_nDisPlayLen = 2000;
}


CMyView::~CMyView()
{
}
BEGIN_MESSAGE_MAP(CMyView, CStatic)
	ON_WM_ERASEBKGND()
	ON_WM_DRAWITEM()
	ON_WM_PAINT()
END_MESSAGE_MAP()


BOOL CMyView::OnEraseBkgnd(CDC* pDC)
{
	// TODO: Add your message handler code here and/or call default
	return true;
	return CStatic::OnEraseBkgnd(pDC);
}

void CMyView::OnPaint()
{
	CPaintDC dc(this); // device context for painting
					   // TODO: Add your message handler code here
	CRect rect;
	GetWindowRect(&rect);
	ScreenToClient(&rect);
	DrawGrid(dc.GetSafeHdc(), rect);
	DrawWave(dc.GetSafeHdc(), rect);
}


void CMyView::PreSubclassWindow()
{
	// TODO: Add your specialized code here and/or call the base class
	DWORD dwStyle = GetStyle();
	SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_OWNERDRAW);
	CStatic::PreSubclassWindow();
	
}
void CMyView::DrawGrid(HDC hDC, RECT rect)
{
	HTDrawGrid(hDC, rect.left, rect.top, rect.right, rect.bottom, 10, 8, 128, 1);
}
void CMyView::DrawWave(HDC hDC, RECT rect)
{
	CDemoVCDlg *pDlg= (CDemoVCDlg *)GetParent();
	if (!pDlg)
		return;
	USHORT nHTriggerPos = pDlg->m_Hard.m_nTriggerHorPos;//水平触发点位置
	USHORT nYTFormat = 0;//二次开发固定0
	USHORT nDisType = 0;//显示类型，点或线
	double dbVertical = 1.0;//二次开发固定1.0
	double dbHorizontal = 1.0;//二次开发固定1.0
	ULONG nDisDataLen = m_nDisPlayLen;// 整个屏幕要画的长度
	ULONG nSrcDataLen = pDlg->m_Hard.m_nReadLen;//源数据的长度
	ULONG nCenterData = nHTriggerPos*nSrcDataLen / 100;//屏幕中间点在SrcData的索引值
	for (int i = 0; i < MAX_CH_NUM; i++)
	{
		if (!pDlg->m_Hard.m_ch[i].bCHEnable)
			continue;
		USHORT nDisLeverPos = pDlg->m_Hard.m_ch[i].m_nLeverPos;
		COLORREF clrRGB = pDlg->m_Hard.m_ch[i].clrRGB;//颜色
		short* pData = pDlg->m_Hard.m_ch[i].m_pDisData;
		HTDrawWaveInYT(hDC, rect, clrRGB, nDisType, pData, nSrcDataLen, nDisDataLen, nCenterData, nDisLeverPos,
			dbHorizontal, dbVertical, nYTFormat, 0);//DLL import
	}
}