📄 rangertestdlg.cpp
字号:
// RangerTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "RangerTest.h"
#include "RangerTestDlg.h"
#include ".\rangertestdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CRangerTestDlg dialog
CRangerTestDlg::CRangerTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRangerTestDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CRangerTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_IMAGEINFO, m_editSessionOutput);
}
BEGIN_MESSAGE_MAP(CRangerTestDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_SHUTDOWN, OnBnClickedShutdown)
ON_BN_CLICKED(IDC_STARTUP, OnBnClickedStartup)
ON_BN_CLICKED(IDC_STARTCAPTURE, OnBnClickedStartcapture)
ON_BN_CLICKED(IDC_STOPCAPTURE, OnBnClickedStopcapture)
ON_BN_CLICKED(IDC_SETUP, OnBnClickedSetup)
END_MESSAGE_MAP()
// CRangerTestDlg message handlers
BOOL CRangerTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CWnd* pMainWnd = AfxGetMainWnd();
// TODO: Add extra initialization here
m_RangerMgr.Initialize();
m_RangerMgr.SetRangerParameter(&m_RangerParameter);
UpdateButtons();
m_RangerMgr.SetObserver(this);
return TRUE; // return TRUE unless you set the focus to a control
}
void CRangerTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CRangerTestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CRangerTestDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
DWORD CRangerTestDlg::OnSessionBegin(const RANGER_SESSION_BEGIN_INFO& info)
{
SSessionInfoEditHelper::Clear(&m_editSessionOutput);
SSessionInfoEditHelper::Append(&m_editSessionOutput,"==== Session Begin ====");
m_nPageReadCount = m_nPageHandleCount = 0;
return -1;
}
DWORD CRangerTestDlg::OnPageBegin(const RANGER_PAGE_BEGIN_INFO& info)
{
m_nPageReadCount++;
CString str;
str.Format("%d",m_nPageReadCount);
GetDlgItem(IDC_READ)->SetWindowText(str);
return -1;
}
DWORD CRangerTestDlg::OnPageEnd(const RANGER_PAGE_END_INFO& info)
{
m_nPageHandleCount++;
CString str;
str.Format("%d",m_nPageHandleCount);
GetDlgItem(IDC_POCKET)->SetWindowText(str);
return -1;
}
CString Transport_ImageSideToString(Transport_ImageSide side)
{
switch(side)
{
case TIS_Front:return "Front";
case TIS_Rear: return "Rear";
default: return "Front";
}
}
CString Transport_ImageColorTypeToString(Transport_ImageColorType side)
{
switch(side)
{
case TI_CT_Bitonal:return "Bitonal";
case TI_CT_Grayscale: return "Grayscale";
case TI_CT_Color:return "Color";
default: return "Bitonal";
}
}
DWORD CRangerTestDlg::OnImageData(const RANGER_IMAGE_DATA_INFO& info)
{
CString str;
SSessionInfoEditHelper::Append(&m_editSessionOutput,"");
// Image Side
str.Format("ImageSide:[%s]",Transport_ImageSideToString(info.eImageSide));
SSessionInfoEditHelper::Append(&m_editSessionOutput,str);
// Image ColorMode
str.Format("ImageColorMode:[%s]",Transport_ImageColorTypeToString(info.eColorMode));
SSessionInfoEditHelper::Append(&m_editSessionOutput,str);
// Image Size
str.Format("ImageSize:[%d]",info.dwImageSize);
SSessionInfoEditHelper::Append(&m_editSessionOutput,str);
// Page ID
str.Format("PageID:[%d]",info.dwPageID);
SSessionInfoEditHelper::Append(&m_editSessionOutput,str);
SSessionInfoEditHelper::Append(&m_editSessionOutput,"");
return -1;
}
DWORD CRangerTestDlg::OnImageError()
{
return -1;
}
DWORD CRangerTestDlg::OnSessionEnd(const RANGER_SESSION_END_INFO& info)
{
SSessionInfoEditHelper::Append(&m_editSessionOutput,"==== Session End ====");
return -1;
}
DWORD CRangerTestDlg::OnError(const RANGER_ERROR& error)
{
return -1;
}
DWORD CRangerTestDlg::OnImageFileBegin(RANGER_IMAGEFILE_BEGIN_INFO& info)
{
return -1;
}
DWORD CRangerTestDlg::OnImageFileEnd(RANGER_IMAGEFILE_END_INFO& info)
{
return -1;
}
// Device Event
DWORD CRangerTestDlg::OnDeviceStartUp()
{
AfxMessageBox("Scanner Startup");
return -1;
}
DWORD CRangerTestDlg::OnPrepareFeeding()
{
return -1;
}
CString TransportstateToString(const TransportState& state)
{
switch(state)
{
case Transport_UnknownState:
return "UnknownState";
case Transport_ShutDown:
return "ShutDown";
case Transport_StartingUp:
return "StartingUp";
case Transport_ChangeOptions:
return "ChangeOptions";
case Transport_EnablingOptions:
return "EnablingOptions";
case Transport_ReadyToFeed:
return "ReadyToFeed";
case Transport_Feeding:
return "Feeding";
case Transport_ExceptionInProgress:
return "ExceptionInProgress";
case Transport_ShuttingDown:
return "ShuttingDown";
}
}
DWORD CRangerTestDlg::OnTransprtStateChanged(const TransportState& state)
{
GetDlgItem(IDC_CURSTATE)->SetWindowText(TransportstateToString(state));
m_TransportState = state;
UpdateButtons();
return -1;
}
DWORD CRangerTestDlg::OnDeviceShutDown()
{
return -1;
}
void CRangerTestDlg::UpdateButtons()
{
GetDlgItem(IDC_STARTUP)->EnableWindow(m_RangerMgr.StartUpAllowed());
GetDlgItem(IDC_STARTCAPTURE)->EnableWindow(m_RangerMgr.StartCaptureAllowed());
GetDlgItem(IDC_SHUTDOWN)->EnableWindow(m_RangerMgr.ShutdownAllowed());
GetDlgItem(IDC_STOPCAPTURE)->EnableWindow(m_RangerMgr.StopAllowed());
GetDlgItem(IDC_SETUP)->EnableWindow(m_RangerMgr.EnableOptionAllowed());
}
void CRangerTestDlg::OnBnClickedStartup()
{
if (!m_RangerMgr.StartUp())
{
AfxMessageBox("Fail to Open Scanner!");
}
}
void CRangerTestDlg::OnBnClickedStartcapture()
{
m_RangerMgr.StartCapture( TFS_MainHopper, TFWM_Continuous);
}
void CRangerTestDlg::OnBnClickedStopcapture()
{
m_RangerMgr.Stop(/*FALSE*/);
}
void CRangerTestDlg::OnBnClickedShutdown()
{
m_RangerMgr.Shutdown();
}
void CRangerTestDlg::OnBnClickedSetup()
{
if (m_RangerParameter.Setup())
AfxMessageBox("Succeed to Enable Option ");
else
AfxMessageBox("Failed to Enable Option ");
// Test: Enable Multistream
//TRANSPORTJOBOPTION* jobOption = m_RangerParameter.GetJobOption();
//jobOption->device.bNeedFrontImages[0] = TRUE;
//jobOption->device.bNeedFrontImages[1] = TRUE;
// Test: Enable Duplex
//TRANSPORTJOBOPTION* jobOption = m_RangerParameter.GetJobOption();
//jobOption->device.bNeedFrontImages[0] = TRUE;
//jobOption->device.bNeedFrontImages[1] = FALSE;
//jobOption->device.bNeedRearImages[0] = TRUE;
//jobOption->device.bNeedRearImages[1] = FALSE;
// Test: Enable File Image
//TRANSPORTJOBOPTION* jobOption = m_RangerParameter.GetJobOption();
//jobOption->Imaging.RootCaptureDirectory = "c:\\image";
//jobOption->FrontImages[0].StorageFile = "FIM";
//jobOption->FrontImages[1].StorageFile = "FIM";
//m_RangerParameter.EnableParameters();
}
void SSessionInfoEditHelper::Clear(CEdit* pEdit)
{
if(pEdit)pEdit->SetWindowText("");
}
void SSessionInfoEditHelper::Append(CEdit* pEdit,LPCSTR lpszInfo)
{
if(pEdit == NULL) return;
CString str;
str.Format("%s\r\n",lpszInfo);
int Length = pEdit->GetWindowTextLength();
pEdit->SetSel(Length, Length);
pEdit->ReplaceSel(str);
pEdit->LineScroll( pEdit->GetLineCount() );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -