// PDFCompDemoDoc.cpp : implementation of the CPDFCompDemoDoc class // #include "stdafx.h" #include "PDFCompDemo.h" #include "PDFCompDemoDoc.h" #include "PDFCompDemoView.h" #include "LEADRaster.h" #include "LEADRasterView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPDFCompDemoDoc IMPLEMENT_DYNCREATE(CPDFCompDemoDoc, CDocument) BEGIN_MESSAGE_MAP(CPDFCompDemoDoc, CDocument) //{{AFX_MSG_MAP(CPDFCompDemoDoc) // 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() ///////////////////////////////////////////////////////////////////////////// // CPDFCompDemoDoc construction/destruction CPDFCompDemoDoc::CPDFCompDemoDoc() { // TODO: add one-time construction code here m_pLEADRaster = NULL; memset(&m_PDFCompSettings, 0, sizeof(m_PDFCompSettings)); m_PDFCompSettings.m_n1Bit = 5; m_PDFCompSettings.m_n2Bit = 0; m_PDFCompSettings.m_nPict = 5; m_PDFCompSettings.m_bCheckBackground = FALSE; m_PDFCompSettings.m_nSeg = 1; m_PDFCompSettings.m_nQFactor = 50; m_PDFCompSettings.nPageNumber= -1; m_bLoaded = FALSE; } CPDFCompDemoDoc::~CPDFCompDemoDoc() { if (m_pLEADRaster) m_pLEADRaster->Release(); } BOOL CPDFCompDemoDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; CPDFCompDemoApp * pApp = (CPDFCompDemoApp *)AfxGetApp(); if (m_pLEADRaster) { m_pLEADRaster->Free(); m_pLEADRaster->Release(); m_pLEADRaster = NULL; } HRESULT hr = CoCreateInstance(CLSID_LEADRaster, NULL, CLSCTX_ALL, IID_ILEADRaster, (void**)&m_pLEADRaster); if (FAILED(hr)) return FALSE; m_pLEADRaster->Bitmap = pApp->m_pRaster->Bitmap; return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CPDFCompDemoDoc serialization void CPDFCompDemoDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CPDFCompDemoDoc diagnostics #ifdef _DEBUG void CPDFCompDemoDoc::AssertValid() const { CDocument::AssertValid(); } void CPDFCompDemoDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CPDFCompDemoDoc commands BOOL CPDFCompDemoDoc::OnOpenDocument(LPCTSTR lpszPathName) { if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; if (!lpszPathName) return FALSE; CPDFCompDemoApp * pApp = (CPDFCompDemoApp *)AfxGetApp(); CPDFCompDemoView * pView = (CPDFCompDemoView *)GetView(); if (m_pLEADRaster) { m_pLEADRaster->Free(); m_pLEADRaster->Release(); m_pLEADRaster = NULL; } HRESULT hr = CoCreateInstance(CLSID_LEADRaster, NULL, CLSCTX_ALL, IID_ILEADRaster, (void**)&m_pLEADRaster); if (FAILED(hr)) return FALSE; int nRet = pApp->m_pRasterIO->Load((LPDISPATCH)m_pLEADRaster, lpszPathName, 0, pApp->m_nPageNum, 1); if(nRet == ERROR_PDF_BAD_INITIALIZATION_FILES) { if( IDYES == MessageBox( AfxGetMainWnd()->m_hWnd, TEXT("LEADTOOLS PDF plugin is not found, do you want to download the plugin now?"), TEXT("Open file"),MB_ICONEXCLAMATION | MB_YESNO)) ShellExecute(AfxGetMainWnd()->m_hWnd, TEXT("open"), TEXT("http://www.leadtools.com/ReleaseDownloads/v14/LEADTOOLSPDFRuntime.exe"), NULL, NULL, SW_SHOWNORMAL); } m_bLoaded = (nRet == 0) ? TRUE : FALSE; return (nRet == 0) ? TRUE : FALSE; } CView * CPDFCompDemoDoc::GetView() { POSITION pos = GetFirstViewPosition(); return GetNextView(pos); } void CPDFCompDemoDoc::OnCloseDocument() { CPDFCompDemoApp * pApp = (CPDFCompDemoApp *)AfxGetApp(); CDocument::OnCloseDocument(); }