// mfcdeDoc.cpp : implementation of the CMfcdemoDoc class // #include "stdafx.h" #include "resdemo.h" #include "browsdlg.h" #include "maindemo.h" #include "mfcdemo.h" #include "colormer.h" #include "mfcdeDoc.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CMfcdemoApp theApp; extern short gnPage; ///////////////////////////////////////////////////////////////////////////// // CMfcdemoDoc IMPLEMENT_DYNCREATE(CMfcdemoDoc, CDocument) BEGIN_MESSAGE_MAP(CMfcdemoDoc, CDocument) //{{AFX_MSG_MAP(CMfcdemoDoc) ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMfcdemoDoc construction/destruction static const WCHAR BASED_CODE _szLicString[] = L"LEADTOOLS OCX Copyright (c) 1991-2001 LEAD Technologies, Inc."; CMfcdemoDoc::CMfcdemoDoc() { CRect rcClient(0,0,1,1); BSTR lpLic = SysAllocString(_szLicString); m_Lead.Create("", 0, rcClient, theApp.m_pMainWnd, 0,NULL,FALSE,lpLic); m_Lead.ShowWindow(SW_HIDE); /* m_Lead2 is used for supporting the floater bitmap in the view */ m_Lead2.Create("", 0, rcClient, theApp.m_pMainWnd, 0,NULL,FALSE,lpLic); m_Lead2.ShowWindow(SW_HIDE); m_LeadUndo.Create("", 0, rcClient, theApp.m_pMainWnd, 0,NULL,FALSE,lpLic); m_LeadUndo.ShowWindow(SW_HIDE); SysFreeString(lpLic); m_nFormat = 5; m_nBits = 0; m_nQFactor = 2; m_nMultipage = 0; m_bPanWin = FALSE; m_bMagGlass = FALSE; m_bStopEffect = TRUE; } CMfcdemoDoc::~CMfcdemoDoc() { m_Lead.DestroyWindow(); // avoid warning messages at debug time m_LeadUndo.DestroyWindow(); // avoid warning messages at debug time } BOOL CMfcdemoDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // handle the exceptions. If an exceptions would occur here, an // invalid document would be created and the list of documents would be // corrupted causing big problems. TRY { switch(theApp.m_nOpenMode) { case OPENMODE_COLORMERGE: return OnOpenColorMerge(); break; case OPENMODE_TWAIN: return(OnOpenTwain()); break; case OPENMODE_ISIS: return(OnOpenIsis()); break; case OPENMODE_BITMAP: return(OnOpenBitmap()); break; case OPENMODE_CAPTURE: return(OnOpenCapture()); break; case OPENMODE_PASTE: return(OnOpenPaste()); break; default: break; } } CATCH_ALL(e) { theApp.DisplayLEADError(ERROR_FAILURE); return FALSE; } END_CATCH_ALL return FALSE; } ///////////////////////////////////////////////////////////////////////////// // CMfcdemoDoc serialization void CMfcdemoDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CMfcdemoDoc diagnostics #ifdef _DEBUG void CMfcdemoDoc::AssertValid() const { CDocument::AssertValid(); } void CMfcdemoDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMfcdemoDoc commands BOOL CMfcdemoDoc::OnOpenDocument(LPCTSTR lpszPathName) { int nRet; m_Lead.SetEnableMethodErrors(FALSE); if(lpszPathName) { if(((CMainFrame*)theApp.m_pMainWnd)->m_pLead->GetBitmap()) { m_Lead.SetRefBitmap(TRUE); m_Lead.SetBitmap(((CMainFrame*)theApp.m_pMainWnd)->m_pLead->GetBitmap()); m_Lead.SetRefBitmap(FALSE); nRet = m_Lead.GetBitmap()?0:ERROR_NO_BITMAP; } else nRet = m_Lead.Load(lpszPathName, 0, gnPage, 1); gnPage = 1; if(nRet) { 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); } } else theApp.DisplayLEADError(nRet); return(FALSE); } m_Lead.GetFileInfo(lpszPathName, gnPage, 0); DisplayDICOMLoadMsg(m_Lead.GetInfoFormat()); return(TRUE); } return(FALSE); } #define DICOM_LOAD_MSG "This demo loads raster images stored in DICOM files.\n" \ "For full DICOM support, refer to the LEADTOOLS Medical Imaging demos." void CMfcdemoDoc::DisplayDICOMLoadMsg(short nFormat) { if(theApp.m_bDICOMLoadMsg) { switch(nFormat) { case FILE_DICOM_GRAY: case FILE_DICOM_COLOR: case FILE_DICOM_RLE_GRAY: case FILE_DICOM_RLE_COLOR: case FILE_DICOM_JPEG_GRAY: case FILE_DICOM_JPEG_COLOR: theApp.m_bDICOMLoadMsg = FALSE; //only do this one time MessageBox(AfxGetMainWnd()->m_hWnd, DICOM_LOAD_MSG, "DICOM Load Information", MB_OK); break; } } return; } BOOL CMfcdemoDoc::OnSaveDocument(LPCTSTR lpszPathName) { int nRet; if(lpszPathName) { nRet = m_Lead.Save((LPSTR)lpszPathName, m_nFormat, m_nBits, m_nQFactor, m_nMultipage); if(nRet) { theApp.DisplayLEADError(nRet); return(FALSE); } SetModifiedFlag(FALSE); return(TRUE); } return(FALSE); } BOOL CMfcdemoDoc::OnOpenCapture() { theApp.m_pMainWnd->ShowWindow (SW_HIDE); theApp.m_pMainWnd->UpdateWindow (); Sleep(1000); CClientDC cdc(theApp.m_pMainWnd->GetDesktopWindow()); m_Lead.Capture((OLE_HANDLE) cdc.m_hDC, 0.0f, 0.0f, (float) cdc.GetDeviceCaps (HORZRES), (float) cdc.GetDeviceCaps (VERTRES)); theApp.m_pMainWnd->ShowWindow (SW_SHOW); return(TRUE); } BOOL CMfcdemoDoc::OnOpenPaste() { m_Lead.Paste(0); return(TRUE); } BOOL CMfcdemoDoc::OnOpenBitmap() { m_Lead.SetBitmap(theApp.m_Bitmap); return(TRUE); } BOOL CMfcdemoDoc::OnOpenTwain() { 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); return(!nRet); } BOOL CMfcdemoDoc::OnOpenIsis() { CLeadIsis LTIsis; RECT rcWin; int nRet; ::SetRect(&rcWin, 0, 0, 1, 1); if(LTIsis.Create(NULL,0,rcWin,theApp.m_pMainWnd,100)) { LTIsis.SetEnableMethodErrors(FALSE); nRet = LTIsis.ISISLoadDriver(); if(nRet == 0) { nRet = LTIsis.ISISAcquire((long)LTIsis.m_hWnd, ISIS_SHOWUI); LTIsis.ISISUnloadDriver(); } if(nRet == 0) { m_Lead.SetBitmap(LTIsis.GetBitmap()); LTIsis.SetBitmap(0); } else if(nRet != ERROR_ISIS_CANCEL) { theApp.DisplayLEADError(nRet); return(FALSE); } } return(TRUE); } BOOL CMfcdemoDoc::OnOpenColorMerge() { CColorMergeDlg dlg(NULL,this); if(dlg.DoModal() == IDOK) { int i; for(i = 0; i < 4; i++) m_Lead.SetColorPlanes(i, ((CMfcdemoDoc*)dlg.m_pDocument[i])->m_Lead.GetBitmap()); m_Lead.ColorMerge(dlg.m_dwFlags); for(i = 0; i < 4; i++) m_Lead.SetColorPlanes(i, 0); return(TRUE); } return(FALSE); } void CMfcdemoDoc::OnFileSaveAs() { BOOL bContinue=FALSE; CString sFileName; int nRet; theApp.m_pRasterFileDlg->PutEnableMethodErrors(FALSE); theApp.m_pRasterFileDlg->PutFileDlgFlags(0); theApp.m_pRasterFileDlg->PutSaveQFactor(2); theApp.m_pRasterFileDlg->PutPageNumber(1); theApp.m_pRasterFileDlg->PutDialogTitle("Save File"); theApp.m_pRasterFileDlg->PutUIFlags( SAVE_SHOW_FILEOPTIONS_MULTIPAGE | SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | SAVE_SHOW_FILEOPTIONS_QFACTOR| SAVE_SHOW_FILEOPTIONS_STAMP | SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| SAVE_SHOW_FILEOPTIONS_J2KOPTIONS); nRet = theApp.m_pRasterFileDlg->ShowSaveDlg((long)theApp.m_pMainWnd->m_hWnd); if(nRet == 0 && theApp.m_pRasterFileDlg->GetDialogStatus() ==DLG_OK) { sFileName = theApp.m_pRasterFileDlg->GetFileName().copy(); m_nFormat = theApp.m_pRasterFileDlg->GetSaveFormat(); m_nBits = theApp.m_pRasterFileDlg->GetSaveBitsPerPixel(); m_nQFactor = theApp.m_pRasterFileDlg->GetSaveQFactor(); m_nMultipage = theApp.m_pRasterFileDlg->GetSaveMulti(); long nPage=1; switch(m_nMultipage) { case SAVE_APPEND: nPage = 2; break; case SAVE_OVERWRITE: nPage = 1; break; case SAVE_REPLACE: case SAVE_INSERT: nPage = theApp.m_pRasterFileDlg->GetPageNumber(); break; } m_Lead.SetSavePage((short)nPage); m_Lead.SetSaveInterlaced(theApp.m_pRasterFileDlg->GetSaveInterlaced()); SetJ2KOptions(); OnSaveDocument((LPCTSTR)sFileName); } else theApp.DisplayLEADError(nRet); return; } BOOL CMfcdemoDoc::CanCloseFrame(CFrameWnd* pFrame) { // TODO: Add your specialized code here and/or call the base class POSITION pos = GetFirstViewPosition(); CMfcdemoView* pView = (CMfcdemoView *)GetNextView(pos); if (!m_bStopEffect) return 0; return CDocument::CanCloseFrame(pFrame); } BOOL CMfcdemoDoc::SaveModified() { if(!IsModified()) return TRUE; // ok to continue // get name/title of document CString name; if(m_strPathName.IsEmpty()) { // get name based on caption name = m_strTitle; if (name.IsEmpty()) VERIFY(name.LoadString(AFX_IDS_UNTITLED)); } else { // get name based on file title of path name name = m_strPathName; } CString prompt; AfxFormatString1(prompt, AFX_IDP_ASK_TO_SAVE, name); switch (AfxMessageBox(prompt, MB_YESNOCANCEL, AFX_IDP_ASK_TO_SAVE)) { case IDCANCEL: break; // don't continue case IDYES: // If so, either Save or Update, as appropriate if (!OnSaveDocument(name)) return FALSE; // don't continue break; case IDNO: // If not saving changes, revert the document break; default: ASSERT(FALSE); break; } return TRUE; // keep going } void CMfcdemoDoc::SetJ2KOptions() { m_Lead.SetJ2KUseColorTransform(theApp.m_pRasterFileDlg->SaveJ2KUseColorTransform); m_Lead.SetJ2KDerivedQuantization(theApp.m_pRasterFileDlg->SaveJ2KDerivedQuantization); m_Lead.SetJ2KCompressionControl(theApp.m_pRasterFileDlg->GetSaveJ2KCompressionControl()); if(theApp.m_pRasterFileDlg->GetSaveJ2KCompressionControl() == J2K_COMP_RATIO) m_Lead.SetJ2KCompressionRatio(theApp.m_pRasterFileDlg->SaveJ2KCompressionRatio); else if(theApp.m_pRasterFileDlg->GetSaveJ2KCompressionControl() == J2K_COMP_TARGETSIZE) m_Lead.SetJ2KTargetFileSize(theApp.m_pRasterFileDlg->SaveJ2KTargetFileSize); m_Lead.SetJ2KXOsiz(theApp.m_pRasterFileDlg->SaveJ2KXOsiz); m_Lead.SetJ2KYOsiz(theApp.m_pRasterFileDlg->SaveJ2KYOsiz); m_Lead.SetJ2KXTsiz(theApp.m_pRasterFileDlg->SaveJ2KXTsiz); m_Lead.SetJ2KYTsiz(theApp.m_pRasterFileDlg->SaveJ2KYTsiz); m_Lead.SetJ2KXTOsiz(theApp.m_pRasterFileDlg->SaveJ2KXTOsiz); m_Lead.SetJ2KYTOsiz(theApp.m_pRasterFileDlg->SaveJ2KYTOsiz); m_Lead.SetJ2KDecompLevel (theApp.m_pRasterFileDlg->SaveJ2KDecompLevel); m_Lead.SetJ2KProgressOrder (theApp.m_pRasterFileDlg->GetSaveJ2KProgressOrder()); m_Lead.SetJ2KCodBlockWidth (theApp.m_pRasterFileDlg->SaveJ2KCodBlockWidth); m_Lead.SetJ2KCodBlockHeight (theApp.m_pRasterFileDlg->SaveJ2KCodBlockHeight); m_Lead.SetJ2KCBS_SelectiveACBypass (theApp.m_pRasterFileDlg->SaveJ2KCBS_SelectiveACBypass); m_Lead.SetJ2KCBS_ResetContextOnBoundaries (theApp.m_pRasterFileDlg->SaveJ2KCBS_ResetContextOnBoundaries); m_Lead.SetJ2KCBS_TerminationOnEachPass (theApp.m_pRasterFileDlg->SaveJ2KCBS_TerminationOnEachPass); m_Lead.SetJ2KCBS_VerticallyCausalContext (theApp.m_pRasterFileDlg->SaveJ2KCBS_VerticallyCausalContext); m_Lead.SetJ2KCBS_PredictableTermination (theApp.m_pRasterFileDlg->SaveJ2KCBS_PredictableTermination); m_Lead.SetJ2KCBS_ErrorResilienceSymbol (theApp.m_pRasterFileDlg->SaveJ2KCBS_ErrorResilienceSymbol); m_Lead.SetJ2KGuardBits (theApp.m_pRasterFileDlg->SaveJ2KGuardBits); m_Lead.SetJ2KDerivedBaseMantissa (theApp.m_pRasterFileDlg->SaveJ2KDerivedBaseMantissa); m_Lead.SetJ2KDerivedBaseExponent (theApp.m_pRasterFileDlg->SaveJ2KDerivedBaseExponent); m_Lead.SetJ2KUseSOPMarker (theApp.m_pRasterFileDlg->SaveJ2KUseSOPMarker); m_Lead.SetJ2KUseEPHMarker (theApp.m_pRasterFileDlg->SaveJ2KUseEPHMarker); }