// OCRUtilDoc.cpp : implementation of the COCRUtilDoc class // #include "stdafx.h" #include "OCRUTIL.h" #include "OCRUtilDoc.h" #include "OCRUtilView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // COCRUtilDoc IMPLEMENT_DYNCREATE(COCRUtilDoc, CDocument) BEGIN_MESSAGE_MAP(COCRUtilDoc, CDocument) //{{AFX_MSG_MAP(COCRUtilDoc) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // COCRUtilDoc construction/destruction COCRUtilDoc::COCRUtilDoc() { // TODO: add one-time construction code here } COCRUtilDoc::~COCRUtilDoc() { } BOOL COCRUtilDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; COCRUtilApp * pTheApp = (COCRUtilApp*)AfxGetApp(); COCRUtilView * pView = (COCRUtilView*)GetView(); if (!pTheApp || !pView) return FALSE; pView->m_bShowPage = FALSE; if (pTheApp->m_Bitmap.Flags.Allocated) { if (pTheApp->m_nPageMode == NEW_PAGE_FROM_TWAIN) { if (pView->AddPage()) { // show the last acquired page L_INT nPageCount = 0; L_DocGetPageCount(pView->m_hDoc, &nPageCount); pView->m_nPageIndex = nPageCount - 1; pView->m_bShowPage = TRUE; pView->m_bImageLoaded = TRUE; pView->UpdateView(); } } } return TRUE; } ///////////////////////////////////////////////////////////////////////////// // COCRUtilDoc serialization void COCRUtilDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // COCRUtilDoc diagnostics #ifdef _DEBUG void COCRUtilDoc::AssertValid() const { CDocument::AssertValid(); } void COCRUtilDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // COCRUtilDoc commands BOOL COCRUtilDoc::OnOpenDocument(LPCTSTR lpszPathName) { if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; COCRUtilApp * pTheApp = (COCRUtilApp*)AfxGetApp(); COCRUtilView * pView = (COCRUtilView*)GetView(); if (!pTheApp || !pView) return FALSE; if (pTheApp->m_Bitmap.Flags.Allocated) { L_FreeBitmap(&pTheApp->m_Bitmap); L_InitBitmap(&pTheApp->m_Bitmap, sizeof(BITMAPHANDLE), 0, 0, 0); } pView->m_bShowPage = FALSE; FILEINFO FileInfo; memset(&FileInfo, 0, sizeof(FILEINFO)); L_INT nRet = L_FileInfo((L_TCHAR *)lpszPathName, &FileInfo, sizeof(FILEINFO), 0, NULL); if (nRet != SUCCESS) return FALSE; LOADFILEOPTION LoadOptions; L_GetDefaultLoadFileOption(&LoadOptions, sizeof(LOADFILEOPTION)); LoadOptions.PageNumber = pTheApp->m_nPageNum; nRet = L_LoadBitmap((L_TCHAR *)lpszPathName, &pTheApp->m_Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, &LoadOptions, NULL); if (nRet == SUCCESS) { pView->m_nPageIndex = - 1; pView->UpdateScrollView(); } return TRUE; } CView * COCRUtilDoc::GetView() { POSITION pos = GetFirstViewPosition(); return GetNextView(pos); }