// 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 "PDFOptions.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 CPDFCompDemoApp::CPDFCompDemoApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance UNLOCKSUPPORT(); m_bShowPreview = TRUE; m_nAddedDocCount = 0; m_bFirstPdfLoaded = FALSE; } ///////////////////////////////////////////////////////////////////////////// // 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; 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(); 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 L_VOID CPDFCompDemoApp::OnFileOpen() { // TODO: Add your command handler code here L_INT nRet; HWND hWndChild = NULL; OPENFILENAME OpenFileName; OPENDLGPARAMS FOParm; memset(&FOParm, 0, sizeof(FOParm)); memset(&OpenFileName, 0, sizeof(OpenFileName)); FOParm.uStructSize = sizeof(FOParm); FOParm.bPreviewEnabled = TRUE; 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 = 0; if(m_bFirstPdfLoaded) { FOParm.uDlgFlags = DLG_OPEN_SHOW_MULTIPAGE | DLG_OPEN_SHOW_PDFOPTIONS | DLG_OPEN_SHOW_FILEINFO | DLG_OPEN_SHOW_LOADOPTIONS | (m_bShowPreview ?DLG_OPEN_SHOW_PREVIEW|DLG_OPEN_USEFILESTAMP:0); } else { FOParm.uDlgFlags = DLG_OPEN_SHOW_MULTIPAGE | DLG_OPEN_SHOW_FILEINFO | DLG_OPEN_SHOW_LOADOPTIONS | (m_bShowPreview ?DLG_OPEN_SHOW_PREVIEW|DLG_OPEN_USEFILESTAMP:0); } nRet = L_DlgOpen( m_pMainWnd->m_hWnd,&OpenFileName,&FOParm); if (nRet == SUCCESS_DLG_OK) { L_GetDefaultLoadFileOption(&m_LoadFileOption, sizeof(LOADFILEOPTION)); m_LoadFileOption.PageNumber = FOParm.pFileData[0].nPageNumber; if( FILE_RAS_PDF == FOParm.pFileData->FileOptions.nType ) { if(!m_bFirstPdfLoaded) { PDFDPIOptions DPIOptions; if( IDOK == DPIOptions.DoModal() ) { ( ( LPOPENDLGOPTIONS_PDF ) FOParm.pFileData [ 0 ].FileOptions.pOptions )->PDFOptions.nXResolution = DPIOptions.m_nXResolution; ( ( LPOPENDLGOPTIONS_PDF ) FOParm.pFileData [ 0 ].FileOptions.pOptions )->PDFOptions.nYResolution = DPIOptions.m_nYResolution; m_bFirstPdfLoaded = TRUE; } else { ( ( LPOPENDLGOPTIONS_PDF ) FOParm.pFileData [ 0 ].FileOptions.pOptions )->PDFOptions.nXResolution = PDFDPI; ( ( LPOPENDLGOPTIONS_PDF ) FOParm.pFileData [ 0 ].FileOptions.pOptions )->PDFOptions.nYResolution = PDFDPI; } } L_SetPDFOptions( &( ( LPOPENDLGOPTIONS_PDF ) FOParm.pFileData [ 0 ].FileOptions.pOptions )->PDFOptions ); } POSITION pos = GetFirstDocTemplatePosition(); CDocTemplate* pDocTemplate = GetNextDocTemplate(pos); pDocTemplate->OpenDocumentFile((LPCTSTR)FOParm.pFileData[0].szFileName); CleanOpenDlgParam(&FOParm); } else if(nRet < 1) PDFCompError(AfxGetApp()->m_pMainWnd->m_hWnd, nRet, TEXT("Open File"), TEXT("")); return; } L_VOID CPDFCompDemoApp::CleanOpenDlgParam(LPOPENDLGPARAMS pFOParam) { L_INT i=0; if(pFOParam!=NULL && pFOParam->pFileData!= NULL ) { for(i=0; i < pFOParam->nNumOfFiles; ++i ) { if(pFOParam->pFileData[i].pBitmap != NULL) { L_FreeBitmap(pFOParam->pFileData[i].pBitmap); GlobalFreePtr(pFOParam->pFileData[i].pBitmap); } if(pFOParam->pFileData[i].pThumbnail != NULL) { L_FreeBitmap(pFOParam->pFileData[i].pThumbnail); GlobalFreePtr(pFOParam->pFileData[i].pThumbnail); } if(pFOParam->pFileData[i].pFileInfo != NULL) { GlobalFreePtr(pFOParam->pFileData[i].pFileInfo); } } GlobalFreePtr(pFOParam->pFileData); pFOParam->pFileData =NULL; pFOParam->nNumOfFiles = 0; } } 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(); while (pos) { CDocTemplate* pTemplate = (CDocTemplate*)GetNextDocTemplate(pos); POSITION 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; POSITION pos = GetFirstDocTemplatePosition(); while (pos) { CDocTemplate* pTemplate = (CDocTemplate*)GetNextDocTemplate(pos); POSITION pos2 = pTemplate->GetFirstDocPosition(); while (pos2) { if ((pDocument=(CPDFCompDemoDoc*)pTemplate->GetNextDoc(pos2)) != NULL) { i++; } } } return i; }