// BarCode.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "BarCode.h" #include "MainFrm.h" #include "ChildFrm.h" #include "BarDoc.h" #include "BarView.h" #include "DlgNew.h" #include "leadbar.h" #include "bar1D.h" #include "PDFRead.h" #include "datmatw.h" #include "qrwrite.h" #include "leadraster.h" #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CBarCodeApp BEGIN_MESSAGE_MAP(CBarCodeApp, CWinApp) //{{AFX_MSG_MAP(CBarCodeApp) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) ON_COMMAND(ID_FILE_ISIS_SELSRC, OnFileIsisSelSrc) ON_UPDATE_COMMAND_UI(ID_FILE_ISIS_SELSRC, OnUpdateFileIsisSelSrc) ON_COMMAND(ID_FILE_ISIS_ACQUIRE, OnFileIsisAcquire) ON_UPDATE_COMMAND_UI(ID_FILE_ISIS_ACQUIRE, OnUpdateFileIsisAcquire) ON_COMMAND(ID_FILE_TWAIN_SELSRC, OnFileTwainSelSrc) ON_COMMAND(ID_FILE_TWAIN_ACQUIRE, OnFileTwainAcquire) ON_COMMAND(ID_EDIT_PASTE, OnEditPaste) ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste) ON_COMMAND(ID_WINDOW_CLOSEALL, OnWindowCloseAll) ON_COMMAND(ID_FILE_OPEN, OnFileOpen) ON_COMMAND(ID_FILE_NEW, OnFileNew) ON_UPDATE_COMMAND_UI(ID_FILE_TWAIN_SELSRC, OnUpdateFileTwainSelsrc) ON_UPDATE_COMMAND_UI(ID_FILE_TWAIN_ACQUIRE, OnUpdateFileTwainAcquire) //}}AFX_MSG_MAP // Standard file based document commands END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CBarCodeApp construction static const WCHAR BASED_CODE _szLicString[] = L"LEADTOOLS OCX Copyright (c) 1991-2004 LEAD Technologies, Inc."; CBarCodeApp::CBarCodeApp() { m_nPage = 1; m_nNewNo = m_nPasteNo = m_nTWAINNo = m_nISISNo = 0; m_bIntialized = FALSE; m_pRasterTwainSink = NULL; // Initalize Read Dialog Options m_nSymbolType = BAR_CODE_1D; m_nMaxCount = 0; m_ulSearchType = BARCODE_1D_READ_ANYTYPE; SetRect(&m_rcSearch, 0, 0, 0, 0); // Initalize Write Dialog Options m_ulBarType = BARCODE_1D_EAN_13; SetRect(&m_rcBar, 50, 50, 400, 150); // Common between Read/Write dialogs m_pReadLeadBar = new CLEADBarCode(); m_pWriteLeadBar = new CLEADBarCode(); m_pRasterIO = NULL; m_pRasterProc = NULL; m_pRasterISIS = NULL; m_pRasterTwain = NULL; } CBarCodeApp::~CBarCodeApp() { if (m_pReadLeadBar) delete m_pReadLeadBar; if (m_pWriteLeadBar) delete m_pWriteLeadBar; } ///////////////////////////////////////////////////////////////////////////// // The one and only CBarCodeApp object CBarCodeApp theApp; ///////////////////////////////////////////////////////////////////////////// // CBarCodeApp initialization BOOL CBarCodeApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif CoInitialize(NULL); // Change the registry key under which our settings are stored. // You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_BARCODTYPE, RUNTIME_CLASS(CBarCodeDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CBarCodeView)); AddDocTemplate(pDocTemplate); // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); //No Child window will be displayed if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew) cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); m_pRasterTwainSink = new CRasterTwainSink(); int nRet=m_RasterView.Create(NULL, 0, CRect(0, 0, 50, 50), m_pMainWnd, 100); m_pReadLeadBar->Create(NULL, 0, CRect(0, 0, 1, 1), m_pMainWnd, 100); m_pWriteLeadBar->Create(NULL, 0, CRect(0, 0, 1, 1), m_pMainWnd, 100); m_RasterView.ShowWindow(SW_HIDE); m_pRaster = NULL; HRESULT hr = CoCreateInstance(CLSID_LEADRaster, NULL, CLSCTX_ALL, IID_ILEADRaster, (void**)&m_pRaster); if (FAILED(hr)) { DisplayLEADError(ERROR_INV_PARAMETER); ExitInstance(); return FALSE; } UNLOCKSUPPORT(*m_pRaster); m_RasterView.SetEnableMethodErrors(FALSE); m_pReadLeadBar->SetEnableMethodErrors(FALSE); m_pReadLeadBar->GetPDFRead().SetDirection(BARCODE_DIR_LEFT_TO_RIGHT); m_pReadLeadBar->GetLinear().SetReadDirection(BARCODE_DIR_HORIZONTAL); m_pReadLeadBar->GetLinear().SetMinLength(3); m_pReadLeadBar->GetLinear().SetGranularity(4); m_pReadLeadBar->GetLinear().SetWhiteLines(3); m_pWriteLeadBar->SetEnableMethodErrors(FALSE); m_pWriteLeadBar->GetLinear().SetEnableWriteText(TRUE); m_pWriteLeadBar->GetLinear().SetEnableErrorCheck(TRUE); m_pWriteLeadBar->GetDataMatrixWrite().SetXModule(30); m_pWriteLeadBar->GetQRWrite().SetGroupNumber(0); m_pWriteLeadBar->GetQRWrite().SetGroupTotal(0); m_pWriteLeadBar->GetQRWrite().SetECCLevel(BARCODE_QR_ECC_L); m_pWriteLeadBar->GetQRWrite().SetXModule(30); m_bIntialized = TRUE; m_pRasterKrnDlg = NULL; hr = CoCreateInstance(CLSID_LEADRasterDlgKrn, NULL, CLSCTX_ALL, IID_ILEADRasterDlgKrn, (void**)&m_pRasterKrnDlg); if (FAILED(hr)) { DisplayLEADError(ERROR_INV_PARAMETER); ExitInstance(); return FALSE; } m_pRasterKrnDlg->InitDlg(INIT_WITH_COLOR); m_pRasterKrnDlg->EnableMethodErrors = FALSE; m_pRasterFileDlg=NULL; hr = CoCreateInstance(CLSID_LEADRasterDlgFile, NULL, CLSCTX_ALL, IID_ILEADRasterDlgFile, (void**)&m_pRasterFileDlg); if (FAILED(hr)) { DisplayLEADError(ERROR_INV_PARAMETER); ExitInstance(); return FALSE; } m_pRasterFileDlg->EnableMethodErrors = FALSE; hr = CoCreateInstance(CLSID_LEADRasterTwain, NULL, CLSCTX_ALL, IID_ILEADRasterTwain, (void**)&m_pRasterTwain); if (SUCCEEDED(hr)) { m_pRasterTwain->InitSession((long)m_pMainWnd->m_hWnd); } LPUNKNOWN pUnkSink = m_pRasterTwainSink->GetIDispatch(FALSE); AfxConnectionAdvise(m_pRasterTwain, DIID__LEADRasterTwainEvents, pUnkSink, FALSE, &m_dwCookie); hr = CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&m_pRasterIO); if (FAILED(hr)) { DisplayLEADError(ERROR_INV_PARAMETER); ExitInstance(); return FALSE; } hr = CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, IID_ILEADRasterProcess, (void**)&m_pRasterProc); if (FAILED(hr)) { DisplayLEADError(ERROR_INV_PARAMETER); ExitInstance(); return FALSE; } hr = CoCreateInstance(CLSID_LEADRasterISIS, NULL, CLSCTX_ALL, IID_ILEADRasterISIS, (void**)&m_pRasterISIS); if (FAILED(hr)) { DisplayLEADError(ERROR_INV_PARAMETER); ExitInstance(); return FALSE; } m_pRasterISIS->put_EnableMethodErrors(FALSE); m_bIsisAvailable = m_pRasterISIS->GetIsISISAvailable(); return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) // No message handlers //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() // App command to run the dialog void CBarCodeApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CBarCodeApp commands int CBarCodeApp::DisplayLEADError(int nCode) { CString str; if (nCode == ERROR_ISIS_CANCEL) nCode = 0; if(nCode) { str.Format("A LEADTOOLS error has occured.\nCODE = %d", nCode); m_pMainWnd->MessageBox(str); } return(nCode); } void CBarCodeApp::OnFileIsisSelSrc() { BeginWaitCursor(); int nRet = m_pRasterISIS->ISISSelect((long)m_pMainWnd->m_hWnd); if (nRet != ERROR_USER_ABORT) DisplayLEADError(nRet); EndWaitCursor(); } void CBarCodeApp::OnUpdateFileIsisSelSrc(CCmdUI* pCmdUI) { pCmdUI->Enable(m_bIsisAvailable); } void CBarCodeApp::OnFileIsisAcquire() { BeginWaitCursor(); int nRet = m_pRasterISIS->ISISLoadDriver(); if (nRet == 0) { nRet = m_pRasterISIS->ISISAcquire((long)m_pMainWnd->m_hWnd, m_pRaster, ISIS_SHOWUI, ISIS_BITMAP_LIST_INSERT); m_pRasterISIS->ISISUnloadDriver(); } if(nRet == 0) { m_RasterView.GetRaster().SetBitmap(m_pRaster->GetBitmap()); m_nISISNo++; m_nDocMode = DOCUMENT_MODE_ISIS; CWinApp::OnFileNew(); } else if(nRet != ERROR_ISIS_CANCEL) DisplayLEADError(nRet); EndWaitCursor(); } void CBarCodeApp::OnUpdateFileIsisAcquire(CCmdUI* pCmdUI) { pCmdUI->Enable(m_bIsisAvailable); } void CBarCodeApp::OnFileTwainSelSrc() { theApp.m_pRasterTwain->EnableMethodErrors = FALSE; int nRet = theApp.m_pRasterTwain->SelectSource(); // show no error if the user clicks on Cancel if (nRet && nRet != ERROR_TWAIN_CANCEL) theApp.DisplayLEADError(nRet); theApp.m_pRasterTwain->EnableMethodErrors = TRUE; } void CBarCodeApp::OnFileTwainAcquire() { CLEADRasterView * pRasterView = theApp.GetMainLead(); theApp.m_pRasterTwain->EnableMethodErrors = FALSE; int nRet = theApp.m_pRasterTwain->Acquire (L_LTWAIN_SHOW_USER_INTERFACE); if (nRet != 0) MessageBox (theApp.m_pMainWnd->m_hWnd, "Error Acquiring From Source", "ERROR", MB_OK); m_RasterView.GetRaster().SetBitmap(pRasterView->GetRaster().GetBitmap()); theApp.m_pRasterTwain->EnableMethodErrors = TRUE; if (nRet) theApp.DisplayLEADError(nRet); else { m_nTWAINNo++; m_nDocMode = DOCUMENT_MODE_TWAIN; CWinApp::OnFileNew(); } EndWaitCursor(); } void CBarCodeApp::OnEditPaste() { BeginWaitCursor(); int nRet = m_RasterView.GetRaster().Paste(0); if (nRet != 0) DisplayLEADError(nRet); else { BeginWaitCursor(); m_nPasteNo++; m_nDocMode = DOCUMENT_MODE_PASTE; CWinApp::OnFileNew(); } EndWaitCursor(); } void CBarCodeApp::OnUpdateEditPaste(CCmdUI* pCmdUI) { pCmdUI->Enable(m_bIntialized && m_RasterView.GetRaster().Paste(PASTE_ISREADY)); } void CBarCodeApp::OnWindowCloseAll() { CloseAllDocuments(FALSE); } void CBarCodeApp::OnFileOpen() { theApp.m_pRasterFileDlg->PutEnableMethodErrors(FALSE); theApp.m_pRasterFileDlg->PutFilter("All Files|*.*"); theApp.m_pRasterFileDlg->PutFileDlgFlags(0); theApp.m_pRasterFileDlg->PutDialogTitle("Open File"); theApp.m_pRasterFileDlg->PutUIFlags(OPEN_SHOW_FILEINFO | OPEN_SHOW_MULTIPAGE | OPEN_SHOW_PREVIEW); int nRet = theApp.m_pRasterFileDlg->ShowOpenDlg((long)m_pMainWnd->m_hWnd); if(nRet == 0 && theApp.m_pRasterFileDlg->GetDialogStatus() == DLG_OK) { m_nPage = (short)theApp.m_pRasterFileDlg->GetPageNumber(); POSITION pos = GetFirstDocTemplatePosition(); CDocTemplate* pDocTemplate = GetNextDocTemplate(pos); pDocTemplate->OpenDocumentFile((LPCTSTR)theApp.m_pRasterFileDlg->GetFileName()); } } void CBarCodeApp::OnFileNew() { CDlgNew * pDlgNew; pDlgNew = new CDlgNew(); if (pDlgNew->DoModal() == IDOK) { BeginWaitCursor(); int nRet = m_RasterView.GetRaster().CreateBitmap((float)pDlgNew->m_nWidth, (float)pDlgNew->m_nHeight, 1); if (nRet != 0) DisplayLEADError(nRet); else { m_pRasterProc->Fill(m_RasterView.GetRaster().m_lpDispatch, RGB(255, 255, 255)); m_nNewNo++; m_nDocMode = DOCUMENT_MODE_NEW; CWinApp::OnFileNew(); } EndWaitCursor(); } delete pDlgNew; } int CBarCodeApp::ExitInstance() { if (m_pRaster) m_pRaster->Release(); if (m_pRasterIO) m_pRasterIO->Release(); if (m_pRasterProc) m_pRasterProc->Release(); if (m_pRasterKrnDlg != NULL) { m_pRasterKrnDlg->FreeDlg(); m_pRasterKrnDlg->Release(); } if (m_pRasterFileDlg != NULL) m_pRasterFileDlg->Release(); LPUNKNOWN pUnkSink = m_pRasterTwainSink->GetIDispatch(FALSE); AfxConnectionUnadvise(m_pRasterTwain, DIID__LEADRasterTwainEvents, pUnkSink, FALSE, m_dwCookie); delete m_pRasterTwainSink; if (m_pRasterTwain != NULL) { m_pRasterTwain->EndSession(); m_pRasterTwain->Release(); } if (m_pRasterISIS) m_pRasterISIS->Release(); CoUninitialize(); return CWinApp::ExitInstance(); } CLEADRasterView * CBarCodeApp::GetMainLead() { CMainFrame* pFrame; pFrame = (CMainFrame*)m_pMainWnd; if(!pFrame) return(NULL); return(pFrame->m_pRasterView); } void CBarCodeApp::OnUpdateFileTwainSelsrc(CCmdUI* pCmdUI) { if(m_pRasterTwain->IsAvailable((long)m_pMainWnd->m_hWnd)) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); } void CBarCodeApp::OnUpdateFileTwainAcquire(CCmdUI* pCmdUI) { if(m_pRasterTwain->IsAvailable((long)m_pMainWnd->m_hWnd)) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); }