// RstDoc.cpp : implementation of the CRstDemoDoc class // #include "stdafx.h" #include "RstDemo.h" #include "RstDoc.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRstDemoDoc IMPLEMENT_DYNCREATE(CRstDemoDoc, CDocument) BEGIN_MESSAGE_MAP(CRstDemoDoc, CDocument) //{{AFX_MSG_MAP(CRstDemoDoc) ON_COMMAND(ID_FILE_SAVE, OnFileSave) ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRstDemoDoc construction/destruction CRstDemoDoc::CRstDemoDoc() { // TODO: add one-time construction code here m_bSaveDocument = TRUE ; } CRstDemoDoc::~CRstDemoDoc() { } BOOL CRstDemoDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; return FALSE; } ///////////////////////////////////////////////////////////////////////////// // CRstDemoDoc serialization void CRstDemoDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CRstDemoDoc diagnostics #ifdef _DEBUG void CRstDemoDoc::AssertValid() const { CDocument::AssertValid(); } void CRstDemoDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CRstDemoDoc commands void CRstDemoDoc::OnFileSave() { POSITION pos = GetFirstViewPosition(); CRstDemoView* pView = (CRstDemoView*) GetNextView(pos); LBitmapBase* pLBtmpbase = pView->m_RasterPntWnd.GetBitmap(); BOOL bFlag = AfxGetMainWnd()->EnableWindow(FALSE); SAVEDLGPARAMS SaveParms ; OPENFILENAME OpenFileName ; memset ( &SaveParms, 0, sizeof ( SAVEDLGPARAMS ) ) ; memset ( &OpenFileName, 0, sizeof ( OPENFILENAME ) ) ; OpenFileName.lStructSize = sizeof ( OPENFILENAME ) ; OpenFileName.lpstrInitialDir = NULL; OpenFileName.lpstrTitle = _T("Save a File"); OpenFileName.nFilterIndex = 0 ; SaveParms.uStructSize = sizeof ( SAVEDLGPARAMS) ; SaveParms.nQFactor = 2 ; SaveParms.nPageNumber = 1 ; SaveParms.nStampBits = 24; SaveParms.nStampWidth = 120; SaveParms.nStampHeight = 120; SaveParms.nBitsPerPixel = 24; SaveParms.nFormat = FILE_BMP; SaveParms.uSaveMulti = MULTIPAGE_OPERATION_REPLACE ; SaveParms.uDlgFlags = DLG_SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE | DLG_SAVE_SHOW_FILEOPTIONS_STAMP | DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR | DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS | DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS ; pLBtmpbase->DialogFile()->SetSaveParams(&SaveParms); pLBtmpbase->DialogFile()->SetOpenFileName(&OpenFileName); pLBtmpbase->DialogFile()->EnableAutoProcess(TRUE); L_INT nRetCode = pLBtmpbase->DialogFile()->DoModalSave(pView->m_hWnd); if(nRetCode!=SUCCESS_DLG_OK && nRetCode!=SUCCESS_DLG_CANCEL) pView->MessageBox(_T("Can't Save to file, check if file is read only."), _T("File Save Error"), MB_ICONWARNING | MB_OK); bFlag = AfxGetMainWnd()->EnableWindow(TRUE); AfxGetMainWnd()->SetActiveWindow(); } void CRstDemoDoc::OnUpdateFileSave(CCmdUI* pCmdUI) { POSITION pos = GetFirstViewPosition(); CRstDemoView* pView = (CRstDemoView*) GetNextView(pos); pCmdUI->Enable(pView->m_RasterPntWnd.GetBitmap()->IsAllocated()); } void CRstDemoDoc::OnCloseDocument() { POSITION pos = GetFirstViewPosition(); CRstDemoView* pView = (CRstDemoView*) GetNextView(pos); if( pView && m_bSaveDocument ) { CString csBuffer; csBuffer.Format(_T("Do you want to save image:\n%s"), pView->m_szFileName); if( (pView->MessageBox( csBuffer, _T("File Save"), MB_ICONWARNING | MB_YESNO) ) == IDYES ) { LBitmapBase* pLBtmpbase = pView->m_RasterPntWnd.GetBitmap(); SAVEDLGPARAMS SaveParms ; OPENFILENAME OpenFileName ; memset ( &SaveParms, 0, sizeof ( SAVEDLGPARAMS ) ) ; OpenFileName.lStructSize = sizeof ( OPENFILENAME ) ; OpenFileName.lpstrInitialDir = NULL; OpenFileName.lpstrTitle = _T("Save a File"); OpenFileName.nFilterIndex = 0 ; SaveParms.uStructSize = sizeof ( SAVEDLGPARAMS) ; SaveParms.nQFactor = 2 ; SaveParms.nPageNumber = 1 ; SaveParms.nStampBits = 24; SaveParms.nStampWidth = 120; SaveParms.nStampHeight = 120; SaveParms.nBitsPerPixel = 24; SaveParms.nFormat = FILE_BMP; SaveParms.uSaveMulti = MULTIPAGE_OPERATION_REPLACE ; SaveParms.uDlgFlags = DLG_SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE | DLG_SAVE_SHOW_FILEOPTIONS_STAMP | DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR | DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS | DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS ; pLBtmpbase->DialogFile()->SetSaveParams(&SaveParms); pLBtmpbase->DialogFile()->SetOpenFileName(&OpenFileName); pLBtmpbase->DialogFile()->EnableAutoProcess(TRUE); pLBtmpbase->DialogFile()->SetFileName(pView->m_szFileName) ; L_INT nRetCode = pLBtmpbase->DialogFile()->DoModalSave(pView->m_hWnd); if(nRetCode!=SUCCESS_DLG_OK && nRetCode!=SUCCESS_DLG_CANCEL) pView->MessageBox(_T("Can't Save to file, check if file is read only."), _T("File Save Error"), MB_ICONWARNING | MB_OK); } } CDocument::OnCloseDocument(); } BOOL CRstDemoDoc::OnOpenDocument(LPCTSTR lpszPathName) { if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; CRstDemoApp* pTheApp = (CRstDemoApp*) AfxGetApp(); POSITION pos = GetFirstViewPosition(); CRstDemoView* pView = (CRstDemoView*)GetNextView(pos); FILEINFO fInfo; OPENDLGPARAMS FOParm; memset(&FOParm, 0, sizeof(OPENDLGPARAMS)); memset(&fInfo, 0, sizeof(FILEINFO)); fInfo.uStructSize = sizeof(FILEINFO); LBitmapBase LBtmpbase; pTheApp->m_LBitmap.DialogFile()->GetOpenParams(&FOParm, sizeof(OPENDLGPARAMS)); LBtmpbase.SetFileName((L_TCHAR L_FAR *)lpszPathName); LBtmpbase.File()->GetInfo(&fInfo, sizeof(FILEINFO), FILEINFO_TOTALPAGES, NULL); L_INT nBitsPerPixel = fInfo.BitsPerPixel; if (nBitsPerPixel != 1 && nBitsPerPixel != 4 && nBitsPerPixel != 8 && nBitsPerPixel != 16 && nBitsPerPixel != 24) { pView->MessageBox(_T("Your image format is not either 1,4,8,16 or 24 bits per pixel"), _T("Error Opening Image"), MB_ICONWARNING | MB_OK); return FALSE; } L_INT nRetCode = LBtmpbase.Load(fInfo.BitsPerPixel, ORDER_BGRORGRAY, (FOParm.pFileData)? FOParm.pFileData[0].nPageNumber : 1); if(nRetCode!=SUCCESS) { if(nRetCode== ERROR_PDF_BAD_INITIALIZATION_FILES) { if( IDYES == MessageBox(AfxGetApp()->m_pMainWnd->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(AfxGetApp()->m_pMainWnd->m_hWnd, TEXT("open"), TEXT("http://www.leadtools.com/ReleaseDownloads/v14/LEADTOOLSPDFRuntime.exe"), NULL, NULL, SW_SHOWNORMAL); } else LBase::DisplayError (NULL, nRetCode); } else { pView->m_RasterPntWnd.SetBitmap(&LBtmpbase); } return ((nRetCode == SUCCESS) ? TRUE : FALSE); }