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

📄 testocxview.cpp

📁 Led识别与统计系统,基于DELPHI 7.0下
💻 CPP
字号:
// TestOcxView.cpp : implementation of the CTestOcxView class
//

#include "stdafx.h"
#include "TestOcx.h"

#include "TestOcxDoc.h"
#include "TestOcxView.h"

#include "Mainfrm.h"
#include "Propertydlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTestOcxView

IMPLEMENT_DYNCREATE(CTestOcxView, CFormView)

BEGIN_MESSAGE_MAP(CTestOcxView, CFormView)
	//{{AFX_MSG_MAP(CTestOcxView)
	ON_COMMAND(ID_GRAB_SINGLE, OnGrabSingle)
	ON_WM_SIZE()
	ON_COMMAND(ID_GRAB_CONTINUOUS, OnGrabContinuous)
	ON_WM_TIMER()
	ON_COMMAND(ID_GRAB_CANCEL, OnGrabCancel)
	ON_COMMAND(ID_WHITE_BALANCE, OnWhiteBalance)
	ON_COMMAND(ID_VIEW_PROPERTIES, OnViewProperties)
	ON_WM_CLOSE()
	ON_COMMAND(ID_FILE_SAVE, OnFileSave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestOcxView construction/destruction

CTestOcxView::CTestOcxView(): 
CFormView(CTestOcxView::IDD),
m_fContinuousGrabActive(false)
{
	//{{AFX_DATA_INIT(CTestOcxView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CTestOcxView::~CTestOcxView()
{
}

void CTestOcxView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestOcxView)
	DDX_Control(pDX, IDC_HVDEVICECTRL, m_Device);
	//}}AFX_DATA_MAP
}

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

	return CFormView::PreCreateWindow(cs);
}

void CTestOcxView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CTestOcxView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CTestOcxView message handlers



void CTestOcxView::OnSize(UINT nType, int cx, int cy) 
{
	CFormView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	if (::IsWindow(m_Device.m_hWnd))
	{
		CRect rc;
		GetClientRect(&rc);
		m_Device.MoveWindow(&rc);
	}
}



void CTestOcxView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
	CString str;
	str.Format("%f", m_Device.GetFrameRate());
	pFrame->GetStatusBar().SetPaneText(1, str, TRUE);

	CFormView::OnTimer(nIDEvent);
}



void CTestOcxView::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	if (m_fContinuousGrabActive	)
	{
		m_Device.GrabCancel();
		KillTimer(TIMERID);
	}
	CFormView::OnClose();
}


void CTestOcxView::OnGrabSingle() 
{
	// TODO: Add your command handler code here
	m_Device.GrabSingle();
	CRect rc;
	m_Device.GetClientRect(&rc);
	m_Device.Draw(rc.left, rc.top, rc.Width(), rc.Height(), 
		rc.left, rc.top, rc.Width(), rc.Height());
}



void CTestOcxView::OnGrabContinuous() 
{
	// TODO: Add your command handler code here
	m_Device.GrabContinuous();
	m_fContinuousGrabActive = true;
	SetTimer(TIMERID, TIMERINTERVAL, NULL);
}


BEGIN_EVENTSINK_MAP(CTestOcxView, CFormView)
    //{{AFX_EVENTSINK_MAP(CTestOcxView)
	ON_EVENT(CTestOcxView, IDC_HVDEVICECTRL, 1 /* GrabContinuousChange */, OnGrabContinuousChange, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()


void CTestOcxView::OnGrabContinuousChange() 
{
	// TODO: Add your control notification handler code here
	CRect rc;
	m_Device.GetClientRect(&rc);
	m_Device.Draw(rc.left, rc.top, rc.Width(), rc.Height(), 
		rc.left, rc.top, rc.Width(), rc.Height());
	m_Device.Continue();
}



void CTestOcxView::OnGrabCancel() 
{
	// TODO: Add your command handler code here
	m_Device.GrabCancel();
	m_fContinuousGrabActive = false;
	KillTimer(TIMERID);
}



void CTestOcxView::OnWhiteBalance() 
{
	// TODO: Add your command handler code here
	m_Device.AutoWhiteBalance();
	m_fContinuousGrabActive = true;
	SetTimer(TIMERID, TIMERINTERVAL, NULL);
}


void CTestOcxView::OnFileSave() 
{
	// TODO: Add your command handler code here
	CFileDialog dlg(FALSE, _T("bmp"), _T("Temp"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Bitmap Files (*.bmp)|*.bmp|JPEG Files (*.jpg)|*.jpg||"));
	if(dlg.DoModal() == IDOK)
		m_Device.SaveImage(dlg.GetPathName());
}


void CTestOcxView::OnViewProperties() 
{
	// TODO: Add your command handler code here
	CPropertyDlg dlg(m_Device);
	dlg.DoModal();
}



⌨️ 快捷键说明

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