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

📄 histdigitview.cpp

📁 AD 数据采集卡基本的采集界面
💻 CPP
字号:
// HistDigitView.cpp : implementation file
//

#include "stdafx.h"
#include "Sys.h"
#include "HistDataDoc.h"
#include "HistDigitView.h"
#include "resource.h"

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

/////////////////////////////////////////////////////////////////////////////
// CHistDigitView

IMPLEMENT_DYNCREATE(CHistDigitView, CListView)

CHistDigitView::CHistDigitView()
{
}

CHistDigitView::~CHistDigitView()
{
}


BEGIN_MESSAGE_MAP(CHistDigitView, CListView)
	ON_WM_CONTEXTMENU()
	//{{AFX_MSG_MAP(CHistDigitView)
	ON_COMMAND(IDM_SixteenShow, OnSixteenShow)
	ON_UPDATE_COMMAND_UI(IDM_SixteenShow, OnUpdateSixteenShow)
	ON_COMMAND(IDM_DigitalVoltShowMode, OnDigitalVoltShowMode)
	ON_UPDATE_COMMAND_UI(IDM_DigitalVoltShowMode, OnUpdateDigitalVoltShowMode)
	ON_COMMAND(IDM_TenShow, OnTenShow)
	ON_UPDATE_COMMAND_UI(IDM_TenShow, OnUpdateTenShow)
	ON_COMMAND(IDM_REFURBISH, OnRefurbish)
	ON_UPDATE_COMMAND_UI(IDM_REFURBISH, OnUpdateRefurbish)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHistDigitView drawing

void CHistDigitView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
	
}
/////////////////////////////////////////////////////////////////////////////
// CHistDigitView diagnostics

#ifdef _DEBUG
void CHistDigitView::AssertValid() const
{
	CListView::AssertValid();
}

void CHistDigitView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
/*CHistDataDoc* CHistDigitView::GetDocument()// non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHistDataDoc)));
	return (CHistDataDoc*)m_pDocument;
}*/
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CHistDigitView message handlers

void CHistDigitView::OnInitialUpdate() 
{
	CListView::OnInitialUpdate();
	DWORD type=LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES|
		LVS_EX_HEADERDRAGDROP | LVS_EX_TRACKSELECT;	//设置listCtrl控件
	GetListCtrl().SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,LPARAM(type));

	nChooseMode=1;

	// TODO: Add your specialized code here and/or call the base class
	CHistDataDoc* pDoc = (CHistDataDoc*)GetDocument();
	pDoc->m_hWndDigit=m_hWnd; 

	CString str;
	CListCtrl& List=GetListCtrl();
	
	UINT Channel;
	int ChannelCount;
	int Row=0, Col=0;
	ChannelCount=32;  

	CHistDataFrm* pFrame=(CHistDataFrm*)GetParentFrame();
	CListBox* pList=(CListBox*)(pFrame->m_wndSetupBar.GetDlgItem(IDC_FILESINFO));
	switch(pDoc->m_Header.BusType)
	{//1:PCI, 2:USB, 3:ISA, 4:PC104
		case PCI_BUS:
			str="BusType:PCI";
			break;
		case USB_BUS:
			str="BusType:USB";
			break;
		case ISA_BUS:
			str="BusType:ISA";
			break;
	}//板卡类型	
	pList->AddString (str);
	str.Format("DeviceID:%x",pDoc->m_Header.DeviceID );
	pList->AddString (str);
	str.Format("HeaderSizeBytes:%d",pDoc->m_Header.HeaderSizeBytes );
	pList->AddString (str);//电压量程
	str.Format("VoltRange %+4.f~%+4.f",pDoc->m_Header.VoltBottomRange,pDoc->m_Header.VoltTopRange);
	pList->AddString(str);	

	str.Format("GroupIterval:%d",pDoc->m_Header.GroupInterval  );
	pList->AddString (str);
	for(int i=0;i<(int)pDoc->m_Header.ChannelCount ;i++)
	{//芯片
		str.Format("Channel[%d]-CH:%d,Ga:%d",i,pDoc->m_Header.ChannelArray[i].ADChannel,pDoc->m_Header.ChannelArray[i].ADGains);
		pList->AddString(str);
	}

	str.Format("ADMode:%d",pDoc->m_Header.ADMode );
	pList->AddString (str);
	str.Format("Frequency:%d",pDoc->m_Header.Frequency);
	pList->AddString (str);//采样频率
	str.Format("TriggerSource:%d",pDoc->m_Header.TriggerSource);
	pList->AddString (str);//触发方式
	str.Format("OutTriggerEdge:%d",pDoc->m_Header.OutTriggerEdge);
	pList->AddString (str);//触发沿
	str.Format("OutDigitAnalog:%d",pDoc->m_Header.OutDigitAnalog );
	pList->AddString (str);

	str.Format("ClockSource:%d",pDoc->m_Header.ClockSource);
	pList->AddString (str);// 同步触发时钟输出允许位


	CEdit* pEditOffset=(CEdit*)(pFrame->m_wndSetupBar.GetDlgItem(IDC_EDIT_Offset));	
	str.Format("%d", pDoc->m_Offset);
	pEditOffset->SetWindowText(str);  // 显示文件偏移

	CEdit* pLength=(CEdit*)(pFrame->m_wndSetupBar.GetDlgItem(IDC_EDIT_FileLength));	
	str.Format("%d", pDoc->m_FileLength);
	pLength->SetWindowText(str);  // 显示文件长度(字)

	
	CSliderCtrl* pSliderOffset=(CSliderCtrl*)(pFrame->m_wndSetupBar.GetDlgItem(IDC_SLIDER_Offset));	

	// 之所以除以通道数,是求出每通道点数
	pSliderOffset->SetRange(0, ((pDoc->m_FileLength-pDoc->m_ReadDataSize)/pDoc->m_ChannelCount));  // 设置滑动条范围(字)
	pSliderOffset->SetPageSize(1000);

	CEdit* pEditPerChannel=(CEdit*)(pFrame->m_wndSetupBar.GetDlgItem(IDC_EDIT_PerChannel));	
    str.Format("%d", pDoc->m_FileLength/pDoc->m_ChannelCount); 
	pEditPerChannel->SetWindowText(str);  // 显示每通道点数

	CComboBox* pRate=(CComboBox*)(pFrame->m_wndSetupBar.GetDlgItem(IDC_COMBO_Rate));	
	pRate->SetCurSel(0);

	CStatic* pLabel=(CStatic*)pFrame->m_wndSetupBar.GetDlgItem(IDC_STATIC_CardType);
	pLabel->SetWindowText(pDoc->m_File.GetFilePath()); ;
	
	m_PerLsbVolt=(pDoc->m_Header.VoltTopRange -pDoc->m_Header.VoltBottomRange)*1000/16384.0;	

	List.InsertColumn(0, "Index" ,LVCFMT_LEFT,42,-1);  // 加入第一列

	for(Channel=0; Channel<pDoc->m_Header.ChannelCount; Channel++)  // 添加通道列		
	{
		str.Format("CH%d", pDoc->m_Header.ChannelArray[Channel].ADChannel);
		List.InsertColumn(Col+1, str ,LVCFMT_LEFT,55,-1);
		Col++;
	}	

	ChannelCount=pDoc->m_Header.ChannelCount;	

	for(Row=0; Row<8192/ChannelCount; Row++)
	{
		str.Format("%d", Row);
		List.InsertItem(Row,str,NULL);  // 添加行号,应一个紧接一个插入	
	} 		
	str.Format("数据回放:%s",pDoc->m_File.GetFileTitle() );
	pDoc->SetTitle(str);
	SetListView();

}

void CHistDigitView::SetListView(void)
{
	CHistDataDoc* pDoc = (CHistDataDoc*)GetDocument();
	CListCtrl& List=GetListCtrl();
	UINT Col=0;
	int Row;
	List.ShowWindow(SW_HIDE);
	List.SetRedraw(FALSE);
	int tmp=pDoc->m_ReadDataSize/pDoc->m_ChannelCount;
	for(Row=0; Row<tmp; Row++)
	{		
		sprintf(str,"%d", pDoc->m_Offset+Row);
		List.SetItemText(Row,0,str);  // 更新Index列
		for(Col=0; Col<(UINT)pDoc->m_ChannelCount; Col++)  
		{
			switch(nChooseMode)
			{
				case 1://十进制显示
					sprintf(str,"%d", (pDoc->m_ADBuffer[Row*pDoc->m_ChannelCount+Col]^0x2000)&0x3fff);	
					break;
				case 2://十六进制显示
					sprintf(str,"%x", (pDoc->m_ADBuffer[Row*pDoc->m_ChannelCount+Col]^0x2000)&0x3fff);	
					break;
				case 3:
					sprintf(str,"%d",(int)((((pDoc->m_ADBuffer[Row*pDoc->m_ChannelCount+Col]^0x2000)&0x3fff)-0x2000)*m_PerLsbVolt));	
					break;
			}
			List.SetItemText(Row,Col+1, str);// 添加各行内容
		} 

	} 
	List.SetRedraw(TRUE);
	List.ShowWindow(SW_SHOW);
}


BOOL CHistDigitView::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	cs.style &= ~(LVS_LIST | LVS_ICON | LVS_SMALLICON);
	cs.style |= LVS_REPORT;
	cs.style |= LVS_SINGLESEL;
	return CListView::PreCreateWindow(cs);
}



void CHistDigitView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	CListView::OnUpdate(pSender, lHint, pHint);
	
}
void CHistDigitView::OnContextMenu(CWnd*, CPoint point)
{
	// CG: This block was added by the Pop-up Menu component	{		if (point.x == -1 && point.y == -1){			//keystroke invocation			CRect rect;			GetClientRect(rect);			ClientToScreen(rect);			point = rect.TopLeft();			point.Offset(5, 5);		}		CMenu menu;		VERIFY(menu.LoadMenu(IDR_HisMouseR));		CMenu* pPopup = menu.GetSubMenu(0);		ASSERT(pPopup != NULL);		CWnd* pWndPopupOwner = this;		while (pWndPopupOwner->GetStyle() & WS_CHILD)			pWndPopupOwner = pWndPopupOwner->GetParent();		pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,			pWndPopupOwner);	}
}

void CHistDigitView::OnSixteenShow() 
{
	// TODO: Add your command handler code here
	//AfxMessageBox("十六进制");
	nChooseMode=2;
	SetListView();//刷新列表
}

void CHistDigitView::OnUpdateSixteenShow(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(nChooseMode==2);	
}

void CHistDigitView::OnDigitalVoltShowMode() 
{
	// TODO: Add your command handler code here
	//AfxMessageBox("电压显示");
	nChooseMode=3;
	SetListView();//刷新列表
}

void CHistDigitView::OnUpdateDigitalVoltShowMode(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(nChooseMode==3);
}

void CHistDigitView::OnTenShow() 
{
	// TODO: Add your command handler code here
	//AfxMessageBox("十进制显示");
	nChooseMode=1;//刷新列表
	SetListView();//刷新列表
}

void CHistDigitView::OnUpdateTenShow(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(nChooseMode==1);
}

void CHistDigitView::OnRefurbish() 
{
	// TODO: Add your command handler code here
	SetListView();//刷新列表
}

void CHistDigitView::OnUpdateRefurbish(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}

⌨️ 快捷键说明

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