// PDFCompDemo.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "PDFCompDemo.h" #include "MainFrm.h" #include "ChildFrm.h" #include "PDFCompDemoDoc.h" #include "PDFCompDemoView.h" #include "PDFCompOptionsDlg.h" #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern L_VOID PDFCompError(HWND hwnd, L_INT nCode, L_TCHAR* pTitle, L_TCHAR* pFilename); ///////////////////////////////////////////////////////////////////////////// // CPDFCompDemoApp BEGIN_MESSAGE_MAP(CPDFCompDemoApp, CWinApp) //{{AFX_MSG_MAP(CPDFCompDemoApp) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) ON_COMMAND(ID_FILE_OPEN, OnFileOpen) //}}AFX_MSG_MAP // Standard file based document commands ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) // Standard print setup command ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPDFCompDemoApp construction BOOL CPDFCompDemoApp::m_bIsPdfDpiSet = FALSE; CPDFCompDemoApp::CPDFCompDemoApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance m_bShowPreview = TRUE; } ///////////////////////////////////////////////////////////////////////////// // The one and only CPDFCompDemoApp object CPDFCompDemoApp theApp; ///////////////////////////////////////////////////////////////////////////// // CPDFCompDemoApp initialization BOOL CPDFCompDemoApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_PDFCOMTYPE, RUNTIME_CLASS(CPDFCompDemoDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CPDFCompDemoView)); AddDocTemplate(pDocTemplate); // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); FILEPDFOPTIONS PdfOptions; memset( &PdfOptions,0,sizeof(FILEPDFOPTIONS)); LFileSettings::GetPDFOptions( &PdfOptions, sizeof(FILEPDFOPTIONS) ); PdfOptions.nXResolution = 150; PdfOptions.nYResolution = 150; LFileSettings::SetPDFOptions( &PdfOptions ); return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) // No message handlers //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() // App command to run the dialog void CPDFCompDemoApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CPDFCompDemoApp message handlers void CPDFCompDemoApp::OnFileOpen() { L_INT nRet = FAILURE; HWND hWndChild = NULL; OPENFILENAME OPENFileName; OPENDLGPARAMS OPENParams; L_TCHAR szFile[256]; POSITION pos ; CDocTemplate* pDocTemplate ; memset(&OPENParams, 0, sizeof(OPENParams)); memset(&OPENFileName, 0, sizeof(OPENFileName)); OPENFileName.lStructSize = sizeof(OPENFileName); OPENFileName.hwndOwner = NULL; OPENFileName.lpstrFilter = NULL; OPENFileName.lpstrCustomFilter = NULL; OPENFileName.nMaxCustFilter = 0; OPENFileName.nFilterIndex = 0; OPENFileName.lpstrInitialDir = NULL; OPENFileName.lpstrTitle = TEXT("OPEN a File"); OPENFileName.nFileOffset = 0; OPENFileName.nFileExtension = 0; OPENFileName.lpstrDefExt = NULL; OPENFileName.Flags = OFN_EXPLORER; OPENParams.bPreviewEnabled = TRUE; OPENParams.uStructSize = sizeof(OPENParams) ; OPENParams.uDlgFlags = DLG_OPEN_SHOW_MULTIPAGE | DLG_OPEN_SHOW_FILEINFO | DLG_OPEN_SHOW_DELPAGE | DLG_OPEN_VIEWTOTALPAGES | DLG_OPEN_SHOW_PDFOPTIONS | DLG_OPEN_SHOW_LOADOPTIONS | (m_bShowPreview ?DLG_OPEN_SHOW_PREVIEW|DLG_OPEN_USEFILESTAMP:0); m_LDlgFile.SetOpenParams(&OPENParams) ; m_LDlgFile.SetOpenFileName(&OPENFileName) ; m_LDlgFile.EnablePreview(TRUE); nRet = m_LDlgFile.DoModalOpen(AfxGetMainWnd()->GetSafeHwnd()) ; if(nRet == SUCCESS_DLG_OK) { m_LDlgFile.GetOpenParams(&OPENParams,sizeof(OPENDLGPARAMS)) ; if(FILE_RAS_PDF == OPENParams.pFileData[0].FileOptions.nType) { LFileSettings::SetPDFOptions(&((LPOPENDLGOPTIONS_PDF)OPENParams.pFileData[0].FileOptions.pOptions)->PDFOptions); if (!m_bIsPdfDpiSet) { CSize resolution ( 0, 0); PDFCompDPIOptionsDlg DPIDlg ; resolution.cx = ((LPOPENDLGOPTIONS_PDF)OPENParams.pFileData[0].FileOptions.pOptions)->PDFOptions.nXResolution; resolution.cy = ((LPOPENDLGOPTIONS_PDF)OPENParams.pFileData[0].FileOptions.pOptions)->PDFOptions.nYResolution; DPIDlg.SetDPIResolution ( resolution ) ; if ( IDOK == DPIDlg.DoModal ( ) ) { FILEPDFOPTIONS PDFOptions; ZeroMemory (&PDFOptions, sizeof(FILEPDFOPTIONS)); LFileSettings::GetPDFOptions(&PDFOptions, sizeof(FILEPDFOPTIONS)); resolution = DPIDlg.GetDPIResolution ( ) ; PDFOptions.nXResolution = resolution.cx; PDFOptions.nYResolution = resolution.cy; LFileSettings::SetPDFOptions(&PDFOptions); m_bIsPdfDpiSet = TRUE; } } } memset(&szFile, 0, sizeof(szFile)); m_LDlgFile.GetFileName(szFile, sizeof(szFile)); pos = GetFirstDocTemplatePosition(); pDocTemplate = GetNextDocTemplate(pos); pDocTemplate->OpenDocumentFile((LPCTSTR)szFile); } else if(nRet < 1) PDFCompError(AfxGetApp()->m_pMainWnd->m_hWnd, nRet, TEXT("Open File"), TEXT("")); } L_VOID CPDFCompDemoApp::SetPageOrder(L_INT nPageNumebr,L_BOOL bRepeated, L_BOOL bDel, L_INT nSwappedPgNo) { CPDFCompDemoDoc* pDocument; CMDIFrameWnd* pFrame = (CMDIFrameWnd* )AfxGetApp()->m_pMainWnd; CMDIChildWnd* pChild = (CMDIChildWnd* ) pFrame->GetActiveFrame(); POSITION pos = GetFirstDocTemplatePosition(); CDocTemplate* pTemplate ; POSITION pos2 ; while (pos) { pTemplate = (CDocTemplate* )GetNextDocTemplate(pos); pos2 = pTemplate->GetFirstDocPosition(); while (pos2) { if ((pDocument=(CPDFCompDemoDoc* )pTemplate->GetNextDoc(pos2)) != NULL) { if(bDel) { if(pDocument->m_PDFCompSettings.nPageNumber > nPageNumebr) pDocument->m_PDFCompSettings.nPageNumber--; } else { if(-1 == nSwappedPgNo) { if(bRepeated && pDocument->m_PDFCompSettings.nPageNumber >= nPageNumebr) { pDocument->m_PDFCompSettings.nPageNumber++; } } else { if(bRepeated && pDocument->m_PDFCompSettings.nPageNumber == nPageNumebr) { pDocument->m_PDFCompSettings.nPageNumber = nSwappedPgNo; } } } } } } //Update all views pChild = (CMDIChildWnd* ) pFrame->GetActiveFrame(); while (pChild) { pChild->Invalidate(); pChild = (CMDIChildWnd* ) pChild->GetWindow(GW_HWNDNEXT); } } L_INT CPDFCompDemoApp::CountAllOpenedDoccuments() { L_INT i=0; CPDFCompDemoDoc* pDocument; CDocTemplate* pTemplate ; POSITION pos2 ; POSITION pos = GetFirstDocTemplatePosition(); while (pos) { pTemplate = (CDocTemplate* )GetNextDocTemplate(pos); pos2 = pTemplate->GetFirstDocPosition(); while (pos2) if ((pDocument=(CPDFCompDemoDoc* )pTemplate->GetNextDoc(pos2)) != NULL) i++; } return i; }