// BarView.cpp : implementation of the CBarCodeView class // #include "stdafx.h" #include "BarCode.h" #include "BarDoc.h" #include "BarView.h" #include "BarROpt.h" #include "BarWOpt.h" #include "DupIndx.h" #include "DlgFLog.h" #include "bardata.h" #include "bar1D.h" #include "pdfread.h" #include "pdfwrite.h" #include "datmatw.h" #include "qrwrite.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CBarCodeApp theApp; ///////////////////////////////////////////////////////////////////////////// // CBarCodeView IMPLEMENT_DYNCREATE(CBarCodeView, CFormView) BEGIN_MESSAGE_MAP(CBarCodeView, CFormView) //{{AFX_MSG_MAP(CBarCodeView) ON_MESSAGE(WM_DOREALIZE, OnDoRealize) ON_WM_CREATE() ON_WM_SIZE() ON_COMMAND(ID_ACTION_READ, OnActionRead) ON_COMMAND(ID_ACTION_WRITE, OnActionWrite) ON_COMMAND(ID_ACTION_DUPLICATEDINFO_FIRST, OnActionDupInfoFirst) ON_UPDATE_COMMAND_UI(ID_ACTION_DUPLICATEDINFO_FIRST, OnUpdateActionDupInfoFirst) ON_COMMAND(ID_ACTION_DUPLICATEDINFO_NEXT, OnActionDupInfoNext) ON_UPDATE_COMMAND_UI(ID_ACTION_DUPLICATEDINFO_NEXT, OnUpdateActionDupInfoNext) ON_COMMAND(ID_ACTIONS_OPENLOGFILE, OnActionsOpenLogFile) ON_UPDATE_COMMAND_UI(ID_ACTIONS_OPENLOGFILE, OnUpdateActionsOpenLogFile) ON_COMMAND(ID_ACTIONS_SETLOGFILE, OnActionsSetLogFile) ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CBarCodeView construction/destruction CBarCodeView::CBarCodeView() : CFormView(CBarCodeView::IDD) { //{{AFX_DATA_INIT(CBarCodeView) //}}AFX_DATA_INIT m_bIsIndexDuplicated = FALSE; m_nDupIndex = 0; m_bLMDown = FALSE; m_uTimerID = 0; } CBarCodeView::~CBarCodeView() { } void CBarCodeView::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CBarCodeView) DDX_Control(pDX, IDC_LEADBARCODE, m_LeadBar); DDX_Control(pDX, IDC_LEADCTRL, m_LeadCtrl); //}}AFX_DATA_MAP } BOOL CBarCodeView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CFormView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CBarCodeView diagnostics #ifdef _DEBUG void CBarCodeView::AssertValid() const { CFormView::AssertValid(); } void CBarCodeView::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } CBarCodeDoc* CBarCodeView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBarCodeDoc))); return (CBarCodeDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CBarCodeView message handlers int CBarCodeView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFormView::OnCreate(lpCreateStruct) == -1) return -1; return 0; } void CBarCodeView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { CBarCodeDoc* pDoc = GetDocument(); m_LeadCtrl.SetAutoRepaint(FALSE); m_LeadCtrl.SetBitmap(GetDocLead()->GetBitmap()); m_LeadCtrl.SetDstRect(m_LeadCtrl.GetDstLeft(), m_LeadCtrl.GetDstTop(), m_LeadCtrl.GetBitmapWidth(), m_LeadCtrl.GetBitmapHeight()); m_LeadCtrl.SetDstClipRect(m_LeadCtrl.GetDstLeft(), m_LeadCtrl.GetDstTop(), m_LeadCtrl.GetDstWidth(), m_LeadCtrl.GetDstHeight()); m_LeadCtrl.SetAutoRepaint(TRUE); } CLead* CBarCodeView::GetDocLead() { CBarCodeDoc* pDoc = GetDocument(); return (&pDoc->m_LeadCtrl); } void CBarCodeView::SetDocLead() { CBarCodeDoc* pDoc = GetDocument(); pDoc->m_LeadCtrl.SetBitmap(m_LeadCtrl.GetBitmap()); } void CBarCodeView::OnSize(UINT nType, int cx, int cy) { CFormView::OnSize(nType, cx, cy); if (IsWindow(m_LeadCtrl.m_hWnd)) m_LeadCtrl.MoveWindow(0, 0, cx, cy); } void CBarCodeView::OnInitialUpdate() { CFormView::OnInitialUpdate(); int xExt = (int)m_LeadCtrl.GetBitmapWidth(), yExt = (int)m_LeadCtrl.GetBitmapHeight(); // Make the CLead control to fit the bitmap and disable CLead's scrolling // Make the form scroll if the window becomes smaller than the bitmap SetScrollSizes(MM_TEXT,CSize(xExt,yExt)); // Make the window fit the image GetParentFrame()->RecalcLayout(); ResizeParentToFit(); // now disable the scroll bars SetScrollSizes(MM_TEXT,CSize(1,1)); CBarCodeDoc* pDoc = GetDocument(); } void CBarCodeView::OnActionRead() { if (m_strLogFileName.IsEmpty()) { int nID = MessageBox("No log file entered, Are you sure?", "Notice!", MB_YESNO); if (nID == IDNO) return; } CBarCodeApp * pTheApp = (CBarCodeApp *)AfxGetApp(); if (!pTheApp) return; CBarReadOpt * pBarROpt = new CBarReadOpt(this, pTheApp->m_nSymbolType, &pTheApp->m_rcSearch, pTheApp->m_nMaxCount, pTheApp->m_ulSearchType, pTheApp->m_pReadLeadBar); if (pBarROpt->DoModal() == IDOK) { BeginWaitCursor(); pTheApp->m_ulSearchType = 0; pTheApp->m_nMaxCount = pBarROpt->m_nMultipleMax; pTheApp->m_nSymbolType = pBarROpt->m_nSymbolType; SetRect(&pTheApp->m_rcSearch, pBarROpt->m_nStartX, pBarROpt->m_nStartY, pBarROpt->m_nWidth + pBarROpt->m_nStartX, pBarROpt->m_nHeight + pBarROpt->m_nStartY); pTheApp->m_pReadLeadBar->SetUnits(pBarROpt->m_nUnits); pTheApp->m_pReadLeadBar->SetEnableUseRegion(pBarROpt->m_bUseRgn); m_LeadBar.SetUnits(pTheApp->m_pReadLeadBar->GetUnits()); m_LeadBar.SetEnableUseRegion(pTheApp->m_pReadLeadBar->GetEnableUseRegion()); if (pBarROpt->m_nSymbolType == BAR_CODE_1D) { pTheApp->m_pReadLeadBar->GetLinear().SetEnableErrorCheck(pBarROpt->m_bErrDigit); pTheApp->m_pReadLeadBar->GetLinear().SetGranularity(pBarROpt->m_nGranularity); pTheApp->m_pReadLeadBar->GetLinear().SetWhiteLines(pBarROpt->m_nWhiteLines); pTheApp->m_pReadLeadBar->GetLinear().SetMinLength(pBarROpt->m_nMinLength); int nDir = 0; if (pBarROpt->m_bDirLefToRight) nDir |= BARCODE_DIR_LEFT_TO_RIGHT; if (pBarROpt->m_bDirRightToLeft) nDir |= BARCODE_DIR_RIGHT_TO_LEFT; if (pBarROpt->m_bDirTopToBtm) nDir |= BARCODE_DIR_TOP_TO_BOTTOM; if (pBarROpt->m_bDirBtmToTop) nDir |= BARCODE_DIR_BOTTOM_TO_TOP; if (pBarROpt->m_bDirSkew) nDir |= BARCODE_DIR_SKEW; if (pBarROpt->m_bDirHoriz) nDir |= BARCODE_DIR_HORIZONTAL; if (pBarROpt->m_bDirVert) nDir |= BARCODE_DIR_VERTICAL; if (pBarROpt->m_bDirDiagonal) nDir |= BARCODE_DIR_DIAGONAL; pTheApp->m_pReadLeadBar->GetLinear().SetReadDirection(nDir); if (pBarROpt->m_bSearchAll) pTheApp->m_ulSearchType = BARCODE_1D_READ_ANYTYPE; else { if (pBarROpt->m_bType1) pTheApp->m_ulSearchType |= BARCODE_1D_EAN_13; if (pBarROpt->m_bType2) pTheApp->m_ulSearchType |= BARCODE_1D_EAN_8; if (pBarROpt->m_bType3) pTheApp->m_ulSearchType |= BARCODE_1D_UPC_A; if (pBarROpt->m_bType4) pTheApp->m_ulSearchType |= BARCODE_1D_UPC_E; if (pBarROpt->m_bType5) pTheApp->m_ulSearchType |= BARCODE_1D_CODE_3_OF_9; if (pBarROpt->m_bType6) pTheApp->m_ulSearchType |= BARCODE_1D_CODE_128; if (pBarROpt->m_bType7) pTheApp->m_ulSearchType |= BARCODE_1D_CODE_I2_OF_5; if (pBarROpt->m_bType8) pTheApp->m_ulSearchType |= BARCODE_1D_CODA_BAR; if (pBarROpt->m_bType9) pTheApp->m_ulSearchType |= BARCODE_1D_UCCEAN_128; if (pBarROpt->m_bType10) pTheApp->m_ulSearchType |= BARCODE_1D_CODE_93; } m_LeadBar.GetLinear().SetEnableErrorCheck(pTheApp->m_pReadLeadBar->GetLinear().GetEnableErrorCheck()); m_LeadBar.GetLinear().SetGranularity(pTheApp->m_pReadLeadBar->GetLinear().GetGranularity()); m_LeadBar.GetLinear().SetWhiteLines(pTheApp->m_pReadLeadBar->GetLinear().GetWhiteLines()); m_LeadBar.GetLinear().SetMinLength(pTheApp->m_pReadLeadBar->GetLinear().GetMinLength()); m_LeadBar.GetLinear().SetReadDirection(pTheApp->m_pReadLeadBar->GetLinear().GetReadDirection()); } else { if (pBarROpt->m_nSymbolType == BAR_CODE_PDF) { pTheApp->m_ulSearchType = BARCODE_PDF417; int nDir = 0; if (pBarROpt->m_bDirLefToRight) nDir |= BARCODE_DIR_LEFT_TO_RIGHT; if (pBarROpt->m_bDirRightToLeft) nDir |= BARCODE_DIR_RIGHT_TO_LEFT; if (pBarROpt->m_bDirTopToBtm) nDir |= BARCODE_DIR_TOP_TO_BOTTOM; if (pBarROpt->m_bDirBtmToTop) nDir |= BARCODE_DIR_BOTTOM_TO_TOP; if (pBarROpt->m_bDirSkew) nDir |= BARCODE_DIR_SKEW; if (pBarROpt->m_bDirHoriz) nDir |= BARCODE_DIR_HORIZONTAL; if (pBarROpt->m_bDirVert) nDir |= BARCODE_DIR_VERTICAL; if (pBarROpt->m_bDirDiagonal) nDir |= BARCODE_DIR_DIAGONAL; pTheApp->m_pReadLeadBar->GetPDFRead().SetDirection(nDir); m_LeadBar.GetPDFRead().SetDirection(pTheApp->m_pReadLeadBar->GetPDFRead().GetDirection()); } else if (pBarROpt->m_nSymbolType == BAR_CODE_DM) { if(pBarROpt->m_bType1) pTheApp->m_ulSearchType |= BARCODE_DM_READ_SQUARE; if(pBarROpt->m_bType2) pTheApp->m_ulSearchType |= BARCODE_DM_READ_RECTANGLE; if(pBarROpt->m_bType3) pTheApp->m_ulSearchType |= BARCODE_DM_READ_SMALL; if (pBarROpt->m_bSearchAll) pTheApp->m_ulSearchType = BARCODE_DM_READ_SQUARE | BARCODE_DM_READ_RECTANGLE| BARCODE_DM_READ_SMALL; } else if (pBarROpt->m_nSymbolType == BAR_CODE_QR) pTheApp->m_ulSearchType = BARCODE_QR_CODE; } m_LeadBar.SetEnableUseColors(pBarROpt->m_bUseColors); m_LeadBar.SetBarColor(pBarROpt->m_dwBarColor); m_LeadBar.SetSpaceColor(pBarROpt->m_dwSpaceColor); m_LeadBar.SetBitmap(m_LeadCtrl.GetBitmap()); m_LeadBar.SetEnableMethodErrors(FALSE); int nRet = m_LeadBar.Read(pTheApp->m_ulSearchType, pTheApp->m_nMaxCount, (short)pTheApp->m_rcSearch.left, (short)pTheApp->m_rcSearch.top, abs(pTheApp->m_rcSearch.right - pTheApp->m_rcSearch.left), abs(pTheApp->m_rcSearch.bottom - pTheApp->m_rcSearch.top)); if (nRet == 0) { CStdioFile *pStdFile = NULL; CString csOutBuffer; int nBarTotal = m_LeadBar.GetTotalCount(); if (!m_strLogFileName.IsEmpty()) { pStdFile = new CStdioFile(m_strLogFileName , CFile::modeCreate | CFile::modeWrite | CFile::typeText); if (!pStdFile) { csOutBuffer.Format("You can not print the Bar Codes results on the Log File."); MessageBox((LPCTSTR)csOutBuffer, "Error!", MB_OK); } } csOutBuffer.Format("Total Bar Code Symbols Found is: %d\n\n", nBarTotal); if (pStdFile) pStdFile->WriteString((LPCTSTR)csOutBuffer); else MessageBox((LPCTSTR)csOutBuffer, "Notice!"); LPCTSTR lpctstrBuffer; for (int i=0; i< nBarTotal; i++) { lpctstrBuffer = csOutBuffer.GetBuffer(m_LeadBar.GetBarCodeData(i).GetLength() + MAX_BUFFER_SIZE); if (!lpctstrBuffer) { MessageBox("Not enough memory.", "Error!"); return; } GetBarCodeDataInfo(i, (CHAR *)lpctstrBuffer); csOutBuffer.ReleaseBuffer(); if (pStdFile) pStdFile->WriteString((LPCTSTR)csOutBuffer); else MessageBox((LPCTSTR)csOutBuffer, "BarCode Info."); } if (pStdFile) { pStdFile->Close(); delete pStdFile; } } else { CBarCodeApp * pTheApp = (CBarCodeApp *)AfxGetApp(); pTheApp->DisplayLEADError(nRet); } m_LeadBar.SetBitmap(0); EndWaitCursor(); } delete pBarROpt; } void CBarCodeView::OnActionWrite() { CBarCodeApp * pTheApp = (CBarCodeApp *)AfxGetApp(); if (!pTheApp) return; CBarWriteOpt * pBarWOpt = new CBarWriteOpt(pTheApp->m_ulBarType, this, &pTheApp->m_rcBar, pTheApp->m_pWriteLeadBar); if (pBarWOpt->DoModal() == IDOK) { BeginWaitCursor(); long ulFlags = 0; int nJustify = 0; SetRect(&pTheApp->m_rcBar, pBarWOpt->m_nStartX, pBarWOpt->m_nStartY, pBarWOpt->m_nStartX + pBarWOpt->m_nWidth, pBarWOpt->m_nStartY + pBarWOpt->m_nHeight); pTheApp->m_ulBarType = pBarWOpt->m_ulBarType; pTheApp->m_pWriteLeadBar->SetUnits(pBarWOpt->m_nUnits); m_LeadBar.SetUnits(pTheApp->m_pWriteLeadBar->GetUnits()); switch (pBarWOpt->m_nSymbType) { case BAR_CODE_1D: pTheApp->m_pWriteLeadBar->GetLinear().SetEnableErrorCheck(pBarWOpt->m_bChkOpt1); pTheApp->m_pWriteLeadBar->GetLinear().SetEnableWriteText(pBarWOpt->m_bChkOpt2); m_LeadBar.GetLinear().SetEnableErrorCheck(pTheApp->m_pWriteLeadBar->GetLinear().GetEnableErrorCheck()); m_LeadBar.GetLinear().SetEnableWriteText(pTheApp->m_pWriteLeadBar->GetLinear().GetEnableWriteText()); break; case BAR_CODE_DM: if (pBarWOpt->m_bChkOpt1) ulFlags |= BARCODE_INITREADER; if (pBarWOpt->m_bChkOpt2) ulFlags |= BARCODE_DISABLE_COMPRESSOPN; if (pBarWOpt->m_bJustifyBottom) nJustify |= BARCODE_JUSTIFY_BOTTOM; if (pBarWOpt->m_bJustifyRight) nJustify |= BARCODE_JUSTIFY_RIGHT; if (pBarWOpt->m_bJustifyHCenter) nJustify |= BARCODE_JUSTIFY_H_CENTER; if (pBarWOpt->m_bJustifyVCenter) nJustify |= BARCODE_JUSTIFY_V_CENTER; pTheApp->m_pWriteLeadBar->SetWriteFlags(ulFlags); pTheApp->m_pWriteLeadBar->GetDataMatrixWrite().SetFlags(nJustify); pTheApp->m_pWriteLeadBar->GetDataMatrixWrite().SetFileIDHigh(pBarWOpt->m_ucFileIdH); pTheApp->m_pWriteLeadBar->GetDataMatrixWrite().SetFileIDLow(pBarWOpt->m_ucFileIdL); pTheApp->m_pWriteLeadBar->GetDataMatrixWrite().SetGroupNumber(pBarWOpt->m_ucGrpNumber); pTheApp->m_pWriteLeadBar->GetDataMatrixWrite().SetGroupTotal(pBarWOpt->m_ucGrpTotal); pTheApp->m_pWriteLeadBar->GetDataMatrixWrite().SetXModule(pBarWOpt->m_nXModule); m_LeadBar.SetWriteFlags(ulFlags); m_LeadBar.GetDataMatrixWrite().SetFlags(nJustify); m_LeadBar.GetDataMatrixWrite().SetFileIDHigh(pBarWOpt->m_ucFileIdH); m_LeadBar.GetDataMatrixWrite().SetFileIDLow(pBarWOpt->m_ucFileIdL); m_LeadBar.GetDataMatrixWrite().SetGroupNumber(pBarWOpt->m_ucGrpNumber); m_LeadBar.GetDataMatrixWrite().SetGroupTotal(pBarWOpt->m_ucGrpTotal); m_LeadBar.GetDataMatrixWrite().SetXModule(pBarWOpt->m_nXModule); break; case BAR_CODE_PDF: if (pBarWOpt->m_bChkOpt1) ulFlags |= BARCODE_TRUNCATE; if (pBarWOpt->m_bChkOpt2) ulFlags |= BARCODE_INITREADER; if (pBarWOpt->m_bChkOpt3) ulFlags |= BARCODE_COLROWASLIMITS; if (pBarWOpt->m_bJustifyBottom) nJustify |= BARCODE_JUSTIFY_BOTTOM; if (pBarWOpt->m_bJustifyRight) nJustify |= BARCODE_JUSTIFY_RIGHT; if (pBarWOpt->m_bJustifyHCenter) nJustify |= BARCODE_JUSTIFY_H_CENTER; if (pBarWOpt->m_bJustifyVCenter) nJustify |= BARCODE_JUSTIFY_V_CENTER; pTheApp->m_pWriteLeadBar->SetWriteFlags(ulFlags); pTheApp->m_pWriteLeadBar->GetPDFWrite().SetJustify(0); pTheApp->m_pWriteLeadBar->GetPDFWrite().SetJustify(nJustify); pTheApp->m_pWriteLeadBar->GetPDFWrite().SetAspectHeight(pBarWOpt->m_nAspectHeight); pTheApp->m_pWriteLeadBar->GetPDFWrite().SetAspectWidth(pBarWOpt->m_nAspectWidth); pTheApp->m_pWriteLeadBar->GetPDFWrite().SetECCPercent(pBarWOpt->m_nEccPercent); pTheApp->m_pWriteLeadBar->GetPDFWrite().SetECCLevel(pBarWOpt->m_nEccLevelData); pTheApp->m_pWriteLeadBar->GetPDFWrite().SetColumns(pBarWOpt->m_nCols); pTheApp->m_pWriteLeadBar->GetPDFWrite().SetModuleAspectRatio(pBarWOpt->m_nModuleRatio); pTheApp->m_pWriteLeadBar->GetPDFWrite().SetModule(pBarWOpt->m_nModuleX); pTheApp->m_pWriteLeadBar->GetPDFWrite().SetRows(pBarWOpt->m_nRows); m_LeadBar.SetWriteFlags(ulFlags); m_LeadBar.GetPDFWrite().SetJustify(0); m_LeadBar.GetPDFWrite().SetJustify(nJustify); m_LeadBar.GetPDFWrite().SetAspectHeight(pBarWOpt->m_nAspectHeight); m_LeadBar.GetPDFWrite().SetAspectWidth(pBarWOpt->m_nAspectWidth); m_LeadBar.GetPDFWrite().SetECCPercent(pBarWOpt->m_nEccPercent); m_LeadBar.GetPDFWrite().SetECCLevel(pBarWOpt->m_nEccLevelData); m_LeadBar.GetPDFWrite().SetColumns(pBarWOpt->m_nCols); m_LeadBar.GetPDFWrite().SetModuleAspectRatio(pBarWOpt->m_nModuleRatio); m_LeadBar.GetPDFWrite().SetModule(pBarWOpt->m_nModuleX); m_LeadBar.GetPDFWrite().SetRows(pBarWOpt->m_nRows); break; case BAR_CODE_QR: if (pBarWOpt->m_bChkOpt1) ulFlags |= BARCODE_INITREADER; if (pBarWOpt->m_bChkOpt2) ulFlags |= BARCODE_DISABLE_COMPRESSOPN; if (pBarWOpt->m_bJustifyBottom) nJustify |= BARCODE_JUSTIFY_BOTTOM; if (pBarWOpt->m_bJustifyRight) nJustify |= BARCODE_JUSTIFY_RIGHT; if (pBarWOpt->m_bJustifyHCenter) nJustify |= BARCODE_JUSTIFY_H_CENTER; if (pBarWOpt->m_bJustifyVCenter) nJustify |= BARCODE_JUSTIFY_V_CENTER; pTheApp->m_pWriteLeadBar->SetWriteFlags(ulFlags); pTheApp->m_pWriteLeadBar->GetQRWrite().SetFlags(nJustify); pTheApp->m_pWriteLeadBar->GetQRWrite().SetGroupNumber(pBarWOpt->m_nQRGrpNum); pTheApp->m_pWriteLeadBar->GetQRWrite().SetGroupTotal(pBarWOpt->m_nQRGrpTot); pTheApp->m_pWriteLeadBar->GetQRWrite().SetXModule(pBarWOpt->m_nQRXModule); pTheApp->m_pWriteLeadBar->GetQRWrite().SetECCLevel(pBarWOpt->m_nQREccLevel); m_LeadBar.SetWriteFlags(ulFlags); m_LeadBar.GetQRWrite().SetFlags(nJustify); m_LeadBar.GetQRWrite().SetGroupNumber(pBarWOpt->m_nQRGrpNum); m_LeadBar.GetQRWrite().SetGroupTotal(pBarWOpt->m_nQRGrpTot); m_LeadBar.GetQRWrite().SetXModule(pBarWOpt->m_nQRXModule); m_LeadBar.GetQRWrite().SetECCLevel(pBarWOpt->m_nQREccLevel); break; } m_LeadBar.SetEnableUseColors(pBarWOpt->m_bUseColors); m_LeadBar.SetEnableTransparent(pBarWOpt->m_bEnableTransparent); m_LeadBar.SetBarColor(pBarWOpt->m_dwBarColor); m_LeadBar.SetSpaceColor(pBarWOpt->m_dwSpaceColor); m_LeadBar.SetBitmap(m_LeadCtrl.GetBitmap()); int nRet = m_LeadBar.Write(pTheApp->m_ulBarType, (LPCTSTR)pBarWOpt->m_strBarData, pTheApp->m_rcBar.left, pTheApp->m_rcBar.top, pTheApp->m_rcBar.right - pTheApp->m_rcBar.left, pTheApp->m_rcBar.bottom - pTheApp->m_rcBar.top); if (nRet == 0) { SetDocLead(); RedrawWindow(); } else { CBarCodeApp * pTheApp = (CBarCodeApp *)AfxGetApp(); pTheApp->DisplayLEADError(nRet); } m_LeadBar.SetBitmap(0); EndWaitCursor(); } delete pBarWOpt; } void CBarCodeView::OnActionDupInfoFirst() { CDupIndex * pDupIndexDlg; pDupIndexDlg = new CDupIndex(); if (pDupIndexDlg->DoModal() == IDOK) { BeginWaitCursor(); m_nDupIndex = pDupIndexDlg->m_nIndex; m_bIsIndexDuplicated = m_LeadBar.IsDuplicated(m_nDupIndex); if (m_bIsIndexDuplicated) { m_nDupIndex = m_LeadBar.GetFirstDuplicated(m_nDupIndex); if ((m_nDupIndex >= 0) && (m_nDupIndex <= ERROR_FAILURE)) { CString csOutBuffer; LPTSTR lptstrBuffer = csOutBuffer.GetBuffer(m_LeadBar.GetBarCodeData(m_nDupIndex).GetData().GetLength() + MAX_BUFFER_SIZE); if (!lptstrBuffer) { MessageBox("Not enough memory ...", "Error!"); } else { GetBarCodeDataInfo(m_nDupIndex, lptstrBuffer); csOutBuffer.ReleaseBuffer(); MessageBox((LPCTSTR)csOutBuffer, "Notice!"); } } else { CBarCodeApp * pTheApp = (CBarCodeApp *)AfxGetApp(); pTheApp->DisplayLEADError(m_nDupIndex); } } else MessageBox("The Bar Code selected by index was not duplicated", "Error!"); EndWaitCursor(); } delete pDupIndexDlg; } void CBarCodeView::OnUpdateActionDupInfoFirst(CCmdUI* pCmdUI) { pCmdUI->Enable(m_LeadBar.GetTotalCount()); } void CBarCodeView::OnActionDupInfoNext() { BeginWaitCursor(); m_nDupIndex = m_LeadBar.GetNextDuplicated(m_nDupIndex); if ((m_nDupIndex >=0) && (m_nDupIndex <= ERROR_FAILURE)) { CString csOutBuffer; LPTSTR lptstrBuffer = csOutBuffer.GetBuffer(m_LeadBar.GetBarCodeData(m_nDupIndex).GetData().GetLength() + MAX_BUFFER_SIZE); if (!lptstrBuffer) MessageBox("Not enough memory.", "Error!"); else { GetBarCodeDataInfo(m_nDupIndex, lptstrBuffer); csOutBuffer.ReleaseBuffer(); MessageBox((LPCTSTR)csOutBuffer, "Notice!"); } } else { CBarCodeApp * pTheApp = (CBarCodeApp *)AfxGetApp(); pTheApp->DisplayLEADError(m_nDupIndex); } EndWaitCursor(); } void CBarCodeView::OnUpdateActionDupInfoNext(CCmdUI* pCmdUI) { pCmdUI->Enable(m_LeadBar.GetTotalCount() && m_bIsIndexDuplicated); } void CBarCodeView::OnActionsSetLogFile() { CDlgLogFile *pDlgLogFile; pDlgLogFile = new CDlgLogFile(); if (pDlgLogFile->DoModal() == IDOK) m_strLogFileName = pDlgLogFile->m_strFileName; delete pDlgLogFile; } void CBarCodeView::OnActionsOpenLogFile() { BeginWaitCursor(); CString csLogFileBuffer; csLogFileBuffer.Format("Notepad.exe %s", (LPCTSTR)m_strLogFileName); WinExec((LPCTSTR)csLogFileBuffer, SW_SHOW); EndWaitCursor(); } void CBarCodeView::OnUpdateActionsOpenLogFile(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_strLogFileName.IsEmpty()); } void CBarCodeView::GetBarCodeDataInfo(int nIndex, CHAR * pszBarInfo) { CString csDestBuff; CHAR szUnits[50]; CHAR szBarType[50]; memset(szUnits, 0, sizeof(szUnits)); memset(szBarType, 0, sizeof(szBarType)); GetBarTypeStr(m_LeadBar.GetBarCodeData(nIndex).GetType(), szBarType); GetBarUnitsStr(m_LeadBar.GetBarCodeData(nIndex).GetUnits(), szUnits); // reserve one extra byte for the NULL terminator LPTSTR lptstrDestBuff = csDestBuff.GetBuffer(m_LeadBar.GetBarCodeData(nIndex).GetLength() + 1); ConvertNULLString((char *)(LPCTSTR)m_LeadBar.GetBarCodeData(nIndex).GetData(), lptstrDestBuff, m_LeadBar.GetBarCodeData(nIndex).GetLength() + 1); wsprintf(pszBarInfo, "No. %d\nData is %s\nType %s\nUnits %s\nPosX %d\nPosY %d\nWidth %d\nHeight %d\n\n", nIndex, lptstrDestBuff, //m_LeadBar.GetBarCodeData(nIndex).GetData(), szBarType, szUnits, m_LeadBar.GetBarCodeData(nIndex).GetLeft(), m_LeadBar.GetBarCodeData(nIndex).GetTop(), m_LeadBar.GetBarCodeData(nIndex).GetWidth(), m_LeadBar.GetBarCodeData(nIndex).GetHeight()); csDestBuff.ReleaseBuffer(); } void CBarCodeView::GetBarTypeStr(long ulBarType, CHAR * pszBarStr) { switch (ulBarType) { case BARCODE_1D_EAN_13: wsprintf(pszBarStr, "EAN 13"); break; case BARCODE_1D_EAN_8: wsprintf(pszBarStr, "EAN 8"); break; case BARCODE_1D_UPC_A: wsprintf(pszBarStr, "UPC A"); break; case BARCODE_1D_UPC_E: wsprintf(pszBarStr, "UPC E"); break; case BARCODE_1D_CODE_3_OF_9: wsprintf(pszBarStr, "Code 3 of 9"); break; case BARCODE_1D_CODE_128: wsprintf(pszBarStr, "Code 128"); break; case BARCODE_1D_CODE_I2_OF_5: wsprintf(pszBarStr, "Interleaved 2 of 5"); break; case BARCODE_1D_CODA_BAR: wsprintf(pszBarStr, "CODABAR"); break; case BARCODE_1D_UCCEAN_128: wsprintf(pszBarStr, "UCCEAN 128"); break; case BARCODE_1D_CODE_93: wsprintf(pszBarStr, "Code 93"); break; case BARCODE_PDF417: wsprintf(pszBarStr, "PDF417"); break; case BARCODE_DM_DEF: wsprintf(pszBarStr, "DM Default"); break; case BARCODE_DM_10x10: wsprintf(pszBarStr, "DM 10x10"); break; case BARCODE_DM_12x12: wsprintf(pszBarStr, "DM 12x12"); break; case BARCODE_DM_14x14: wsprintf(pszBarStr, "DM 14x14"); break; case BARCODE_DM_16x16: wsprintf(pszBarStr, "DM 16x16"); break; case BARCODE_DM_18x18: wsprintf(pszBarStr, "DM 18x18"); break; case BARCODE_DM_20x20: wsprintf(pszBarStr, "DM 20x20"); break; case BARCODE_DM_22x22: wsprintf(pszBarStr, "DM 22x22"); break; case BARCODE_DM_24x24: wsprintf(pszBarStr, "DM 24x24"); break; case BARCODE_DM_26x26: wsprintf(pszBarStr, "DM 26x26"); break; case BARCODE_DM_32x32: wsprintf(pszBarStr, "DM 32x32"); break; case BARCODE_DM_36x36: wsprintf(pszBarStr, "DM 36x36"); break; case BARCODE_DM_40x40: wsprintf(pszBarStr, "DM 40x40"); break; case BARCODE_DM_44x44: wsprintf(pszBarStr, "DM 44x44"); break; case BARCODE_DM_48x48: wsprintf(pszBarStr, "DM 48x48"); break; case BARCODE_DM_52x52: wsprintf(pszBarStr, "DM 52x52"); break; case BARCODE_DM_64x64: wsprintf(pszBarStr, "DM 64x64"); break; case BARCODE_DM_72x72: wsprintf(pszBarStr, "DM 72x72"); break; case BARCODE_DM_80x80: wsprintf(pszBarStr, "DM 80x80"); break; case BARCODE_DM_88x88: wsprintf(pszBarStr, "DM 88x88"); break; case BARCODE_DM_96x96: wsprintf(pszBarStr, "DM 96x96"); break; case BARCODE_DM_104x104: wsprintf(pszBarStr, "DM 10x104"); break; case BARCODE_DM_120x120: wsprintf(pszBarStr, "DM 120x120"); break; case BARCODE_DM_132x132: wsprintf(pszBarStr, "DM 132x132"); break; case BARCODE_DM_144x144: wsprintf(pszBarStr, "DM 144x144"); break; case BARCODE_DM_8x18: wsprintf(pszBarStr, "DM 8x18"); break; case BARCODE_DM_8x32: wsprintf(pszBarStr, "DM 8x32"); break; case BARCODE_DM_12x26: wsprintf(pszBarStr, "DM 12x26"); break; case BARCODE_DM_12x36: wsprintf(pszBarStr, "DM 12x36"); break; case BARCODE_DM_16x36: wsprintf(pszBarStr, "DM 16x36"); break; case BARCODE_DM_16x48: wsprintf(pszBarStr, "DM 48x48"); break; case BARCODE_DM_WRITE_RECTANGLE: wsprintf(pszBarStr, "DM Default Rect"); break; case BARCODE_QR_DEF: wsprintf(pszBarStr, TEXT("QR DEF")); break; case BARCODE_QR_M2_1: wsprintf(pszBarStr, TEXT("QR M2 1")); break; case BARCODE_QR_M2_2: wsprintf(pszBarStr, TEXT("QR M2 2")); break; case BARCODE_QR_M2_3: wsprintf(pszBarStr, TEXT("QR M2 3")); break; case BARCODE_QR_M2_4: wsprintf(pszBarStr, TEXT("QR M2 4")); break; case BARCODE_QR_M2_5: wsprintf(pszBarStr, TEXT("QR M2 5")); break; case BARCODE_QR_M2_6: wsprintf(pszBarStr, TEXT("QR M2 6")); break; case BARCODE_QR_M2_7: wsprintf(pszBarStr, TEXT("QR M2 7")); break; case BARCODE_QR_M2_8: wsprintf(pszBarStr, TEXT("QR M2 8")); break; case BARCODE_QR_M2_9: wsprintf(pszBarStr, TEXT("QR M2 9")); break; case BARCODE_QR_M2_10: wsprintf(pszBarStr, TEXT("QR M2 10")); break; case BARCODE_QR_M2_11: wsprintf(pszBarStr, TEXT("QR M2 11")); break; case BARCODE_QR_M2_12: wsprintf(pszBarStr, TEXT("QR M2 12")); break; case BARCODE_QR_M2_13: wsprintf(pszBarStr, TEXT("QR M2 13")); break; case BARCODE_QR_M2_14: wsprintf(pszBarStr, TEXT("QR M2 14")); break; case BARCODE_QR_M2_15: wsprintf(pszBarStr, TEXT("QR M2 15")); break; case BARCODE_QR_M2_16: wsprintf(pszBarStr, TEXT("QR M2 16")); break; case BARCODE_QR_M2_17: wsprintf(pszBarStr, TEXT("QR M2 17")); break; case BARCODE_QR_M2_18: wsprintf(pszBarStr, TEXT("QR M2 18")); break; case BARCODE_QR_M2_19: wsprintf(pszBarStr, TEXT("QR M2 19")); break; case BARCODE_QR_M2_20: wsprintf(pszBarStr, TEXT("QR M2 20")); break; case BARCODE_QR_M2_21: wsprintf(pszBarStr, TEXT("QR M2 21")); break; case BARCODE_QR_M2_22: wsprintf(pszBarStr, TEXT("QR M2 22")); break; case BARCODE_QR_M2_23: wsprintf(pszBarStr, TEXT("QR M2 23")); break; case BARCODE_QR_M2_24: wsprintf(pszBarStr, TEXT("QR M2 24")); break; case BARCODE_QR_M2_25: wsprintf(pszBarStr, TEXT("QR M2 25")); break; case BARCODE_QR_M2_26: wsprintf(pszBarStr, TEXT("QR M2 26")); break; case BARCODE_QR_M2_27: wsprintf(pszBarStr, TEXT("QR M2 27")); break; case BARCODE_QR_M2_28: wsprintf(pszBarStr, TEXT("QR M2 28")); break; case BARCODE_QR_M2_29: wsprintf(pszBarStr, TEXT("QR M2 29")); break; case BARCODE_QR_M2_30: wsprintf(pszBarStr, TEXT("QR M2 30")); break; case BARCODE_QR_M2_31: wsprintf(pszBarStr, TEXT("QR M2 31")); break; case BARCODE_QR_M2_32: wsprintf(pszBarStr, TEXT("QR M2 32")); break; case BARCODE_QR_M2_33: wsprintf(pszBarStr, TEXT("QR M2 33")); break; case BARCODE_QR_M2_34: wsprintf(pszBarStr, TEXT("QR M2 34")); break; case BARCODE_QR_M2_35: wsprintf(pszBarStr, TEXT("QR M2 35")); break; case BARCODE_QR_M2_36: wsprintf(pszBarStr, TEXT("QR M2 36")); break; case BARCODE_QR_M2_37: wsprintf(pszBarStr, TEXT("QR M2 37")); break; case BARCODE_QR_M2_38: wsprintf(pszBarStr, TEXT("QR M2 38")); break; case BARCODE_QR_M2_39: wsprintf(pszBarStr, TEXT("QR M2 39")); break; case BARCODE_QR_M2_40: wsprintf(pszBarStr, TEXT("QR M2 40")); break; case BARCODE_QR_M1_1: wsprintf(pszBarStr, TEXT("QR M1 1")); break; case BARCODE_QR_M1_2: wsprintf(pszBarStr, TEXT("QR M1 2")); break; case BARCODE_QR_M1_3: wsprintf(pszBarStr, TEXT("QR M1 3")); break; case BARCODE_QR_M1_4: wsprintf(pszBarStr, TEXT("QR M1 4")); break; case BARCODE_QR_M1_5: wsprintf(pszBarStr, TEXT("QR M1 5")); break; case BARCODE_QR_M1_6: wsprintf(pszBarStr, TEXT("QR M1 6")); break; case BARCODE_QR_M1_7: wsprintf(pszBarStr, TEXT("QR M1 7")); break; case BARCODE_QR_M1_8: wsprintf(pszBarStr, TEXT("QR M1 8")); break; case BARCODE_QR_M1_9: wsprintf(pszBarStr, TEXT("QR M1 9")); break; case BARCODE_QR_M1_10: wsprintf(pszBarStr, TEXT("QR M1 10")); break; case BARCODE_QR_M1_11: wsprintf(pszBarStr, TEXT("QR M1 11")); break; case BARCODE_QR_M1_12: wsprintf(pszBarStr, TEXT("QR M1 12")); break; case BARCODE_QR_M1_13: wsprintf(pszBarStr, TEXT("QR M1 13")); break; case BARCODE_QR_M1_14: wsprintf(pszBarStr, TEXT("QR M1 14")); break; case BARCODE_QR_M1_DEF: wsprintf(pszBarStr, TEXT("QR M1 DEF")); break; } } void CBarCodeView::GetBarUnitsStr(int nUnits, CHAR * pszBarUnits) { switch (nUnits) { case BARCODE_SCANLINES_PER_PIXELS: wsprintf(pszBarUnits, "Scans/pixels"); break; case BARCODE_INCHES: wsprintf(pszBarUnits, "Inches"); break; case BARCODE_MILLIMETERS: wsprintf(pszBarUnits, "Millimeters"); break; } } void CBarCodeView::SetRectRgn(void) { m_LeadCtrl.SetRgnFrameType(2); m_LeadCtrl.SetRgnRect((float)(m_rcRgn.left + m_LeadCtrl.GetScrollPos(SB_HORZ)), (float)(m_rcRgn.top + m_LeadCtrl.GetScrollPos(SB_VERT)), (float)(m_rcRgn.right - m_rcRgn.left), (float)(m_rcRgn.bottom - m_rcRgn.top), L_RGN_SET); } void CBarCodeView::DrawRect() { CDC * pDC = GetDC(); pDC->SetROP2(R2_NOT); pDC->MoveTo(m_rcFrame.left, m_rcFrame.top); pDC->LineTo(m_rcFrame.right, m_rcFrame.top); pDC->LineTo(m_rcFrame.right, m_rcFrame.bottom); pDC->LineTo(m_rcFrame.left, m_rcFrame.bottom); pDC->LineTo(m_rcFrame.left, m_rcFrame.top); ReleaseDC(pDC); } BEGIN_EVENTSINK_MAP(CBarCodeView, CFormView) //{{AFX_EVENTSINK_MAP(CBarCodeView) ON_EVENT(CBarCodeView, IDC_LEADCTRL, -606 /* MouseMove */, OnMouseMoveLeadCtrl, VTS_I2 VTS_I2 VTS_I4 VTS_I4) ON_EVENT(CBarCodeView, IDC_LEADCTRL, -605 /* MouseDown */, OnMouseDownLeadCtrl, VTS_I2 VTS_I2 VTS_I4 VTS_I4) ON_EVENT(CBarCodeView, IDC_LEADCTRL, -607 /* MouseUp */, OnMouseUpLeadCtrl, VTS_I2 VTS_I2 VTS_I4 VTS_I4) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() void CBarCodeView::OnMouseMoveLeadCtrl(short Button, short Shift, long x, long y) { if (m_bLMDown) { DrawRect(); m_rcFrame.right = x; m_rcFrame.bottom = y; DrawRect(); } } void CBarCodeView::OnMouseDownLeadCtrl(short Button, short Shift, long x, long y) { if (Button != 1) return; if (m_LeadCtrl.GetHasRgn()) { m_LeadCtrl.FreeRgn(); InvalidateRect(NULL); UpdateWindow(); } m_bLMDown = TRUE; m_rcFrame.right = m_rcFrame.left = x; m_rcFrame.bottom = m_rcFrame.top = y; DrawRect(); } void CBarCodeView::OnMouseUpLeadCtrl(short Button, short Shift, long x, long y) { if (Button != 1) return; m_bLMDown = FALSE; DrawRect(); if ((m_rcFrame.left == m_rcFrame.right) || (m_rcFrame.top == m_rcFrame.bottom)) return; SetRect(&m_rcRgn, min(m_rcFrame.left, m_rcFrame.right), min(m_rcFrame.top, m_rcFrame.bottom), max(m_rcFrame.left, m_rcFrame.right), max(m_rcFrame.top, m_rcFrame.bottom)); SetRectRgn(); } void CBarCodeView::OnDestroy() { if (m_LeadCtrl.GetHasRgn()) m_LeadCtrl.FreeRgn(); CFormView::OnDestroy(); } void CBarCodeView::ConvertNULLString(char * pszSrcBuf, char * pszDestBuf, int nBufCount) { int n = 0; while (n < nBufCount) { if(pszSrcBuf[n] == '\0') pszDestBuf[n] = ' '; else pszDestBuf[n] = pszSrcBuf[n]; n++; } pszDestBuf[nBufCount - 1] = '\0'; } void CBarCodeView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView); if (bActivate) { ASSERT(pActivateView == this); OnDoRealize((WPARAM)theApp.m_pMainWnd->m_hWnd, (LPARAM) FALSE); // same as SendMessage(WM_DOREALIZE); } } LRESULT CBarCodeView::OnDoRealize(WPARAM wParam, LPARAM lParam) { if( !IsWindow(m_LeadCtrl.m_hWnd) || !m_LeadCtrl.GetBitmap() ) return FALSE; if(lParam) { return m_LeadCtrl.SendMessage(WM_PALETTECHANGED, wParam); } else { return m_LeadCtrl.SendMessage(WM_QUERYNEWPALETTE,0); } }