// 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 "lead.h" //#include "leaddlg.h" #include "leadisis.h" #include "leadbar.h" #include "bar1D.h" #include "PDFRead.h" #include "datmatw.h" #include "qrwrite.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-2001 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(); } 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 // 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 CRasterTwainSink1; int nRet=m_Lead.Create(NULL, 0, CRect(0, 0, 50, 50), m_pMainWnd, 100); m_LTIsis.Create(NULL, 0, CRect(0, 0, 1, 1), 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_Lead.ShowWindow(SW_HIDE); UNLOCKSUPPORT(m_Lead); m_Lead.SetEnableMethodErrors(FALSE); m_LTIsis.SetEnableMethodErrors(FALSE); // m_Lead.SetEnableTwainFeeder(TRUE); // m_Lead.SetEnableTwainAutoFeed(TRUE); // m_Lead.SetTwainMaxPages(-1); // m_Lead.TwainRealize((OLE_HANDLE)m_pMainWnd->m_hWnd); 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_bIsisAvailable = m_LTIsis.GetIsISISAvailable(); m_bIntialized = TRUE; CoInitialize(NULL); HRESULT hr; m_pRasterKrnDlg = NULL; hr = CoCreateInstance( CLSID_LEADRasterDlgKrn_D, NULL, CLSCTX_ALL, IID_ILEADRasterDlgKrn_D, (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_D, NULL, CLSCTX_ALL, IID_ILEADRasterDlgFile_D, (void**)&m_pRasterFileDlg ); if (FAILED(hr)){DisplayLEADError(ERROR_INV_PARAMETER);ExitInstance(); return FALSE;} m_pRasterFileDlg->EnableMethodErrors = FALSE; hr = CoCreateInstance(CLSID_LEADRasterTwain_D, NULL, CLSCTX_ALL, IID_ILEADRasterTwain_D, (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_D, pUnkSink, FALSE, &m_dwCookie); 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() { CLeadIsis LTIsis; RECT rcWin; int nRet; BeginWaitCursor(); SetRect(&rcWin, 0, 0, 1, 1); if (LTIsis.Create(NULL, 0, rcWin, m_pMainWnd, 100)) { nRet = LTIsis.ISISSelect((long)LTIsis.m_hWnd); if (nRet != ERROR_USER_ABORT) DisplayLEADError(nRet); } EndWaitCursor(); } void CBarCodeApp::OnUpdateFileIsisSelSrc(CCmdUI* pCmdUI) { pCmdUI->Enable(m_bIsisAvailable); } void CBarCodeApp::OnFileIsisAcquire() { int nRet; BeginWaitCursor(); nRet = m_LTIsis.ISISLoadDriver(); if (nRet == 0) { nRet = m_LTIsis.ISISAcquire((long)m_LTIsis.m_hWnd, ISIS_SHOWUI); m_LTIsis.ISISUnloadDriver(); } if(nRet == 0) { m_Lead.SetBitmap(m_LTIsis.GetBitmap()); m_LTIsis.SetBitmap(0); 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() { //CLead *pLead = GetMainLead(); 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() { int nRet; CLead* pLead = theApp.GetMainLead(); theApp.m_pRasterTwain->EnableMethodErrors = FALSE; 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_Lead.SetBitmap(pLead->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_Lead.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_Lead.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_Lead.CreateBitmap((float)pDlgNew->m_nWidth, (float)pDlgNew->m_nHeight, 1); if (nRet != 0) DisplayLEADError(nRet); else { m_Lead.Fill(RGB(255, 255, 255)); m_nNewNo++; m_nDocMode = DOCUMENT_MODE_NEW; CWinApp::OnFileNew(); } EndWaitCursor(); } delete pDlgNew; } int CBarCodeApp::ExitInstance() { m_pRasterKrnDlg->FreeDlg(); if (m_pRasterKrnDlg != NULL) m_pRasterKrnDlg->Release(); if (m_pRasterFileDlg != NULL) m_pRasterFileDlg->Release(); LPUNKNOWN pUnkSink = m_pRasterTwainSink->GetIDispatch(FALSE); AfxConnectionUnadvise(m_pRasterTwain, DIID__LEADRasterTwainEvents_D, pUnkSink, FALSE, m_dwCookie); delete m_pRasterTwainSink; if (m_pRasterTwain != NULL) { m_pRasterTwain->EndSession(); m_pRasterTwain->Release(); } CoUninitialize(); return CWinApp::ExitInstance(); } CLead* CBarCodeApp::GetMainLead() { CMainFrame* pFrame; pFrame = (CMainFrame*)m_pMainWnd; if(!pFrame) return(NULL); return(pFrame->m_pLead); } 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); }