📄 displayview.cpp
字号:
// displayView.cpp : implementation of the CDisplayView class
//
#include "stdafx.h"
#include "display.h"
#include "displayDoc.h"
#include "displayView.h"
#include "control.h"
//#include "d:\Cypress\usb\drivers\ezusbdrv\ezusbsys.h"
#include "ezusbsys.h"
#include "winioctl.h"
#include <process.h>
//#include "string.h"
//#include <windows.h>
//#include <malloc.h>
//#include <assert.h>
//#include <stdlib.h>
//#include <stdio.h>
//#include <process.h>
//#include "resource.h"
//#include "isomax.h"
//#include <winioctl.h>
//#include "ezusbsys.h"
#include "submain.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDisplayView
IMPLEMENT_DYNCREATE(CDisplayView, CScrollView)
BEGIN_MESSAGE_MAP(CDisplayView, CScrollView)
//{{AFX_MSG_MAP(CDisplayView)
ON_WM_PAINT()
ON_WM_TIMER()
ON_COMMAND(IDC_VIEW_DISP, OnViewDisp)
ON_COMMAND(IDC_VIEW_CONTINUE, OnViewContinue)
ON_COMMAND(IDC_STOP_ALL, OnStopAll)
ON_COMMAND(IDC_COLOR, OnColor)
ON_COMMAND(IDC_GRAY, OnGray)
ON_COMMAND(IDC_ISO_READ, OnIsoRead)
ON_COMMAND(IDC_DEBUG, OnDebug)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDisplayView construction/destruction
CDisplayView::CDisplayView()
{
// TODO: add construction code here
m_data=0;
m_tmp=0;
gray_flag=0;
high=0;
}
CDisplayView::~CDisplayView()
{
if((WaitForSingleObject(m_heventdone[0],0)!=WAIT_OBJECT_0)
||(WaitForSingleObject(m_heventdone[1],0)!=WAIT_OBJECT_0)
||(WaitForSingleObject(m_heventdone[2],0)!=WAIT_OBJECT_0)
||(WaitForSingleObject(m_heventdone[3],0)!=WAIT_OBJECT_0)
||(WaitForSingleObject(m_heventdone[4],0)!=WAIT_OBJECT_0)
||(WaitForSingleObject(m_heventdone[5],0)!=WAIT_OBJECT_0)
)
{
SetEvent(m_heventbuttonok);
return ;
}
}
BOOL CDisplayView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDisplayView drawing
void CDisplayView::OnDraw(CDC* pDC)
{
CDisplayDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//pDC->StretchBlt(x,y,nw,nh,&m_dc,0,0,nsw,nsh,SRCCOPY);
//SetDIBitsToDevice(
//StretchDIBits()
LPSTR lpdibhdr;
LPSTR lpdibbits;
BOOL bSuccess=false;
if (pDoc->m_hDib==NULL)
return;
if(gray_flag==0)
{
lpdibhdr=(LPSTR)::GlobalLock(pDoc->m_hDib);
lpdibbits=(LPSTR)::GlobalLock(pDoc->m_hDib);
lpdibbits+=pDoc->length;
lpdibhdr+=sizeof(BITMAPFILEHEADER);
::SetStretchBltMode(*pDC,COLORONCOLOR);
bSuccess=::SetDIBitsToDevice(
*pDC,0,0,640,480,0,0,0,480,lpdibbits,
(LPBITMAPINFO)lpdibhdr,DIB_RGB_COLORS);
}
else
{
lpdibhdr=(LPSTR)::GlobalLock(pDoc->m_hDib);
lpdibhdr+=sizeof(BITMAPFILEHEADER);
DrawGray2D(pDC,(HANDLE)(lpdibhdr),high);
}
CString str;
str.Format("%03d",m_tmp);
CRect rect;
rect.top=10;
rect.bottom=30;
rect.left=690;
rect.right=790;
pDC->DrawText(str,&rect,DT_CENTER);
CTime time=CTime::GetCurrentTime();
rect.top=50;
rect.bottom=70;
str.Format("%02d:%02d:%02d",time.GetHour(),time.GetMinute(),time.GetSecond());
pDC->DrawText(str,&rect,DT_CENTER);
}
void CDisplayView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
SetTimer(1,100,NULL);
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CDisplayView printing
BOOL CDisplayView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDisplayView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDisplayView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDisplayView diagnostics
#ifdef _DEBUG
void CDisplayView::AssertValid() const
{
CScrollView::AssertValid();
}
void CDisplayView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CDisplayDoc* CDisplayView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDisplayDoc)));
return (CDisplayDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDisplayView message handlers
void CDisplayView::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDisplayDoc* pDoc = GetDocument();
// TODO: Add your message handler code here
LPSTR lpdibhdr;
LPSTR lpdibbits;
BOOL bSuccess=false;
if (pDoc->m_hDib==NULL)
return;
if(gray_flag==0)
{
lpdibhdr=(LPSTR)::GlobalLock(pDoc->m_hDib);
lpdibbits=(LPSTR)::GlobalLock(pDoc->m_hDib);
lpdibbits+=pDoc->length;
lpdibhdr+=sizeof(BITMAPFILEHEADER);
::SetStretchBltMode(dc,COLORONCOLOR);
bSuccess=::SetDIBitsToDevice(
dc,0,0,640,480,0,0,0,480,lpdibbits,
(LPBITMAPINFO)lpdibhdr,DIB_RGB_COLORS);
}
else
{
lpdibhdr=(LPSTR)::GlobalLock(pDoc->m_hDib);
lpdibhdr+=sizeof(BITMAPFILEHEADER);
DrawGray2D(&dc,(HANDLE)(lpdibhdr),high);
}
CString str;
str.Format("%03d",m_tmp);
CRect rect;
rect.top=10;
rect.bottom=30;
rect.left=690;
rect.right=790;
dc.DrawText(str,&rect,DT_CENTER);
CTime time=CTime::GetCurrentTime();
rect.top=50;
rect.bottom=70;
str.Format("%02d:%02d:%02d",time.GetHour(),time.GetMinute(),time.GetSecond());
dc.DrawText(str,&rect,DT_CENTER);
// Do not call CScrollView::OnPaint() for painting messages
}
void CDisplayView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
// this->RedrawWindow(NULL,NULL,RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE);
// this->OnUpdate(NULL,0,0);
if (nIDEvent==1)
{
// this->SetRedraw(true);
// this->Invalidate(false);
}
CScrollView::OnTimer(nIDEvent);
}
void CDisplayView::OnViewDisp()
{
// TODO: Add your command handler code here
CDisplayDoc* pDoc = GetDocument();
pDoc->phand=NULL;
char devicename[]="Ezusb-0";
if(!pDoc->bOpenDriver(&pDoc->phand,devicename))
{
MessageBox("打开设备出错","信息提示",MB_OK);
// flag=0;
return ;
}
if(pDoc->m_hDib==NULL)
{
MessageBox("未初始化图象","信息提示",MB_OK);
return ;
}
LPSTR pDib = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDib);
BULK_TRANSFER_CONTROL bulk;
WORD inPacketSize=1024*30;
int sucess;
ULONG nBytes=0;
bulk.pipeNum=1;
pDoc->m_data=0;
while(pDoc->m_data<1024*300)
{
sucess=DeviceIoControl
(pDoc->phand,IOCTL_EZUSB_BULK_READ,
&bulk,
sizeof(BULK_TRANSFER_CONTROL),
pDib+sizeof(BITMAPINFO)+pDoc->m_data,
inPacketSize,
&nBytes,
NULL);
if(!sucess)
{
MessageBox("读数据错误!","信息提示",MB_OK);
return ;
}
else
{
pDoc->m_data+=1024*30;
// pdlg->m_data%=(1024*300);
}
}
//添加代码
::GlobalUnlock((HGLOBAL) pDoc->m_hDib);
// Sleep(10);
this->SetRedraw(true);
this->Invalidate(false);
}
UINT vdatagather(LPVOID pParam)
{
//数据采集
CDisplayView *pdlg=(CDisplayView *)pParam;
if(pdlg==NULL||
!pdlg->IsKindOf(RUNTIME_CLASS(CDisplayView)))
return 2;
ResetEvent(pdlg->m_heventdone[0]);
while(WaitForSingleObject(pdlg->m_heventbuttonok,0)!=WAIT_OBJECT_0)
{
if(WaitForSingleObject(pdlg->m_hsem,INFINITE)==WAIT_OBJECT_0)
{
LPSTR pDib = (LPSTR) ::GlobalLock((HGLOBAL) pdlg->GetDocument()->m_hDib);
pDib+=pdlg->GetDocument()->length;
BULK_TRANSFER_CONTROL bulk;
WORD inPacketSize=1024*60;
// int i;
int sucess;
ULONG nBytes=0;
bulk.pipeNum=2;
pdlg->m_data=0;
while(pdlg->m_data<1024*300)
{
sucess=DeviceIoControl
(pdlg->GetDocument()->phand,IOCTL_EZUSB_BULK_READ,
&bulk,
sizeof(BULK_TRANSFER_CONTROL),
pDib+pdlg->m_data,
inPacketSize,
&nBytes,
NULL);
if(!sucess)
{
MessageBox(NULL,"读数据错误!","信息提示",MB_OK);
return 3;
}
else
{
pdlg->m_data+=1024*60;
// if(pdlg->m_data>=1024*300)
// {
// pdlg->m_data=0;
// pdlg->SetRedraw(true);
// pdlg->Invalidate(false);
// }
}
}
pdlg->SetRedraw(true);
pdlg->Invalidate(false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -