// SegDemoDoc.cpp : implementation of the CSegDemoDoc class // #include "stdafx.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CSegDemoApp theApp; extern void ExitMFCApp(); ///////////////////////////////////////////////////////////////////////////// // CSegDemoDoc IMPLEMENT_DYNCREATE(CSegDemoDoc, CDocument) BEGIN_MESSAGE_MAP(CSegDemoDoc, CDocument) //{{AFX_MSG_MAP(CSegDemoDoc) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSegDemoDoc construction/destruction CSegDemoDoc::CSegDemoDoc() { HRESULT hr; //Create the licensed LTRaster COM object m_pRaster = NULL; hr = theApp.CreateRasterObjectLic(&m_pRaster); if (FAILED(hr)){theApp.DisplayLEADError(ERROR_INV_PARAMETER);ExitMFCApp(); return;} m_pRasterMrc = NULL; hr = CoCreateInstance( CLSID_LEADRasterMrc, NULL, CLSCTX_ALL, IID_ILEADRasterMrc, (void**)&m_pRasterMrc ); if (FAILED(hr)){theApp.DisplayLEADError(ERROR_INV_PARAMETER);ExitMFCApp(); return;} m_pRasterMrc->EnableMethodErrors = FALSE; m_pRasterSegmentationSink= new CRasterSegmentationSink; LPUNKNOWN pUnkSink = m_pRasterSegmentationSink->GetIDispatch(FALSE); AfxConnectionAdvise(m_pRasterMrc, DIID__LEADRasterMrcEvents ,pUnkSink, FALSE, &m_dwCookie); } CSegDemoDoc::~CSegDemoDoc() { if (m_pRasterMrc != NULL) m_pRasterMrc->Release(); m_pRaster->Release(); } BOOL CSegDemoDoc::OnNewDocument() { if(theApp.m_nOpenMode == OPENMODE_PASTE) { SetTitle(TEXT("Clipboard Data")); } if (!CDocument::OnNewDocument()) return FALSE; switch(theApp.m_nOpenMode) { case OPENMODE_PASTE: return OnOpenPaste(); case OPENMODE_BITMAP: return OnOpenBitmap(); } return TRUE; } BOOL CSegDemoDoc::OnOpenBitmap() { m_pRaster->Bitmap = theApp.m_pBitmap; return(TRUE); } BOOL CSegDemoDoc::OnOpenPaste() { m_pRaster->Paste(PASTE_DOPASTE); return(TRUE); } ///////////////////////////////////////////////////////////////////////////// // CSegDemoDoc serialization void CSegDemoDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CSegDemoDoc diagnostics #ifdef _DEBUG void CSegDemoDoc::AssertValid() const { CDocument::AssertValid(); } void CSegDemoDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CSegDemoDoc commands BOOL CSegDemoDoc::OnOpenDocument(LPCTSTR lpszPathName) { if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; int nRet; if(lpszPathName) { UNLOCKSUPPORT(*m_pRaster); if(((CMainFrame*)theApp.m_pMainWnd)->m_pRaster->GetBitmap()) { m_pRaster->put_RefBitmap(TRUE); m_pRaster->put_Bitmap(((CMainFrame*)theApp.m_pMainWnd)->m_pRaster->GetBitmap()); m_pRaster->put_RefBitmap(FALSE); nRet = m_pRaster->GetBitmap()?0:ERROR_NO_BITMAP; } else { if(!theApp.m_bOpenMRC) nRet = theApp.m_pRasterIO->Load(m_pRaster, lpszPathName, 0, theApp.m_iPage, 1); else nRet = m_pRasterMrc->Load(m_pRaster, lpszPathName, theApp.m_iPage); } theApp.m_iPage = 1; if(nRet) { theApp.DisplayLEADError(nRet); return(FALSE); } theApp.m_pRasterIO->GetFileInfo(m_pRaster, lpszPathName, theApp.m_iPage, 0); return(TRUE); } return(FALSE); }