www.pudn.com > PtBarcodeDec.rar > SampleDoc.cpp
// SampleDoc.cpp : implementation of the CSampleDoc class
//
#include "stdafx.h"
#include "Sample.h"
#include "SampleDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSampleDoc
IMPLEMENT_DYNCREATE(CSampleDoc, CDocument)
BEGIN_MESSAGE_MAP(CSampleDoc, CDocument)
//{{AFX_MSG_MAP(CSampleDoc)
ON_COMMAND(ID_ACTION_DECODE_PDF417, OnActionDecodePdf417)
ON_UPDATE_COMMAND_UI(ID_ACTION_DECODE_PDF417, OnUpdateActionDecodePdf417)
ON_COMMAND(ID_ACTION_DECODE_QRCODE, OnActionDecodeQrcode)
ON_UPDATE_COMMAND_UI(ID_ACTION_DECODE_QRCODE, OnUpdateActionDecodeQrcode)
ON_COMMAND(ID_ACTION_DECODE_DATAMATRIX, OnActionDecodeDatamatrix)
ON_UPDATE_COMMAND_UI(ID_ACTION_DECODE_DATAMATRIX, OnUpdateActionDecodeDatamatrix)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSampleDoc construction/destruction
CSampleDoc::CSampleDoc()
{
// TODO: add one-time construction code here
PtPDF417DecodeRegister("12345678901234567890");//use the license key of demo version.
PtQRDecodeRegister ("12345678901234567890");//use the license key of demo version.
PtDMDecodeRegister ("12345678901234567890");//use the license key of demo version.
PtInitImage(&m_image);
m_scale=1.0;
}
CSampleDoc::~CSampleDoc()
{
PtFreeImage(&m_image);
}
BOOL CSampleDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CSampleDoc serialization
void CSampleDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CSampleDoc diagnostics
#ifdef _DEBUG
void CSampleDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CSampleDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSampleDoc commands
BOOL CSampleDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
PtFreeImage(&m_image);//free the memory used for storing the last image
int ret=PtLoadImage( lpszPathName, &m_image, 0 );
if( ret!= PT_IMAGERW_SUCCESS )
::AfxMessageBox("open file error ");
m_scale=1.0;
UpdateAllViews(NULL);
return TRUE;
}
void CSampleDoc::ShowBarCodeInfo( PTTOTALBARCODEINFO* pBarCodeInfo )
{
if( pBarCodeInfo->dwTotalCount<=0 )
{
::AfxMessageBox("No barcode was found");
return;
}
int count;
char ch[200];
sprintf( ch, "Find %d barcodes\n\n", pBarCodeInfo->dwTotalCount );
CString str = ch;
for( count=0; countdwTotalCount); count++)
{
int i;
sprintf( ch, "barcode %d:\n", count+1 );
str += ch;
for( i=0; ipInfoList[count].dwDataLen); i++)
str += pBarCodeInfo->pInfoList[count].pData[i];
str+="\nHex: ";
for( i=0; ipInfoList[count].dwDataLen); i++)
{
sprintf( ch, "%x%x ", pBarCodeInfo->pInfoList[count].pData[i]>>4&0x0F, pBarCodeInfo->pInfoList[count].pData[i]&0x0F);
str += ch;
}
str+="\n\n";
}
::AfxMessageBox(str);
UpdateAllViews(NULL);
}
void CSampleDoc::OnActionDecodePdf417()
{
CWaitCursor wait;
PTDECODEPARA DecodePara;
DecodePara.dwStartX = 0;
DecodePara.dwStartY = 0;
DecodePara.dwEndX = 0;
DecodePara.dwEndY = 0;//search the whole image.
DecodePara.dwMaxCount= 0;//search the all symbols in the image.
PTTOTALBARCODEINFO BarCodeInfo;
PtPDF417DecodeInit( &BarCodeInfo );
if( PtPDF417DecodeFromFile ( GetPathName(), &DecodePara, &BarCodeInfo ) != PT_PDF417DECODE_SUCCESS )
::AfxMessageBox("An error occured while rocognition ");
else
ShowBarCodeInfo( &BarCodeInfo );
PtPDF417DecodeFree( &BarCodeInfo );
}
void CSampleDoc::OnActionDecodeQrcode()
{
CWaitCursor wait;
PTDECODEPARA DecodePara;
DecodePara.dwStartX = 0;
DecodePara.dwStartY = 0;
DecodePara.dwEndX = 0;
DecodePara.dwEndY = 0;//search the whole image.
DecodePara.dwMaxCount= 0;//search the all symbols in the image.
PTTOTALBARCODEINFO BarCodeInfo;
PtQRDecodeInit( &BarCodeInfo );
if( PtQRDecodeFromFile ( GetPathName(), &DecodePara, &BarCodeInfo ) != PT_QRDECODE_SUCCESS )
::AfxMessageBox("An error occured while rocognition ");
else
ShowBarCodeInfo( &BarCodeInfo );
PtQRDecodeFree( &BarCodeInfo );
}
void CSampleDoc::OnActionDecodeDatamatrix()
{
CWaitCursor wait;
PTDECODEPARA DecodePara;
DecodePara.dwStartX = 0;
DecodePara.dwStartY = 0;
DecodePara.dwEndX = 0;
DecodePara.dwEndY = 0;//search the whole image.
DecodePara.dwMaxCount= 0;//search the all symbols in the image.
PTTOTALBARCODEINFO BarCodeInfo;
PtDMDecodeInit( &BarCodeInfo );
if( PtDMDecodeFromFile ( GetPathName(), &DecodePara, &BarCodeInfo ) != PT_DMDECODE_SUCCESS )
::AfxMessageBox("An error occured while rocognition ");
else
ShowBarCodeInfo( &BarCodeInfo );
PtDMDecodeFree( &BarCodeInfo );
}
void CSampleDoc::OnUpdateActionDecodePdf417(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_image.pBits==NULL)
pCmdUI->Enable(FALSE);
else
pCmdUI->Enable(TRUE);
}
void CSampleDoc::OnUpdateActionDecodeQrcode(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_image.pBits==NULL)
pCmdUI->Enable(FALSE);
else
pCmdUI->Enable(TRUE);
}
void CSampleDoc::OnUpdateActionDecodeDatamatrix(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_image.pBits==NULL)
pCmdUI->Enable(FALSE);
else
pCmdUI->Enable(TRUE);
}