// TwainDoc.cpp : implementation of the CTwainDoc class // #include "stdafx.h" #include "Twain.h" #include "TwainDoc.h" #include "TwainView.h" #include "LEADRaster.h" #include "LEADRasterView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTwainDoc IMPLEMENT_DYNCREATE(CTwainDoc, CDocument) BEGIN_MESSAGE_MAP(CTwainDoc, CDocument) //{{AFX_MSG_MAP(CTwainDoc) // 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() ///////////////////////////////////////////////////////////////////////////// // CTwainDoc construction/destruction CTwainDoc::CTwainDoc() { // TODO: add one-time construction code here m_pLEADRaster = NULL; } CTwainDoc::~CTwainDoc() { if (m_pLEADRaster) m_pLEADRaster->Release(); } BOOL CTwainDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; CTwainApp * pApp = (CTwainApp *)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; } ///////////////////////////////////////////////////////////////////////////// // CTwainDoc serialization void CTwainDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CTwainDoc diagnostics #ifdef _DEBUG void CTwainDoc::AssertValid() const { CDocument::AssertValid(); } void CTwainDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CTwainDoc commands BOOL CTwainDoc::OnOpenDocument(LPCTSTR lpszPathName) { if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; if (!lpszPathName) return FALSE; CTwainApp * pApp = (CTwainApp *)AfxGetApp(); CTwainView * pView = (CTwainView *)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); return (nRet == 0) ? TRUE : FALSE; } CView * CTwainDoc::GetView() { POSITION pos = GetFirstViewPosition(); return GetNextView(pos); }