/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 14 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c)1991-2004 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ #include "stdafx.h" #include "ABC.h" #include "MainFrm.h" #include "ChildFrm.h" #include "ABCDoc.h" #include "ABCView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CABCApp BEGIN_MESSAGE_MAP(CABCApp, CWinApp) //{{AFX_MSG_MAP(CABCApp) 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) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CABCApp construction CABCApp::CABCApp() { m_nPaintScaling = Paint_Normal; lstrcpy(m_szFileName, TEXT("")); lstrcpy(m_szOpenedFileName, TEXT("")); lstrcpy(m_szImageDir, TEXT("c:\\\0")); memset( &m_OpenFileName,0, sizeof(m_OpenFileName) ); m_OpenFileName.lStructSize = sizeof(OPENFILENAME); m_OpenFileName.lpstrInitialDir = NULL; m_OpenFileName.lpstrTitle = TEXT("Save a File"); m_OpenFileName.nFileOffset = 0; m_OpenFileName.Flags = 0; m_nPageNumber = 0; m_bCombine = FALSE; m_Quality = -1; lstrcpy( m_szQuality, TEXT("") ); m_nDisplayMode = 0 ; } ///////////////////////////////////////////////////////////////////////////// // The one and only CABCApp object CABCApp theApp; ///////////////////////////////////////////////////////////////////////////// // CABCApp initialization BOOL CABCApp::InitInstance() { #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. // You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("LEAD Technologies, Inc.")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) CString cs; cs = GetProfileString(TEXT("Settings"), TEXT("ImageDir"), TEXT("c:\\")); lstrcpy(m_szImageDir, (LPCTSTR)cs); // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_ABCTYPE, RUNTIME_CLASS(CABCDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CABCView)); 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); // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); WINDOWPLACEMENT wndpl; // This code is just to maximize the windoe.. if( pMainFrame->GetWindowPlacement( &wndpl ) ) { wndpl.showCmd = SW_SHOWMAXIMIZED; pMainFrame->SetWindowPlacement( &wndpl ); } return TRUE; } int CABCApp::ExitInstance() { // TODO: Add your specialized code here and/or call the base class return CWinApp::ExitInstance(); } ///////////////////////////////////////////////////////////////////////////// // 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) //}}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) //}}AFX_MSG_MAP END_MESSAGE_MAP() // App command to run the dialog void CABCApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } /*--------------------------------------------------------------------------+ | Function :CleanOpenDlgParam | Desc :free | Return :void | Notes : +--------------------------------------------------------------------------*/ L_VOID CABCApp::CleanOpenDlgParam(LPOPENDLGPARAMS pFOParam) { int i=0; LBitmap DumpBitmap; if(pFOParam!=NULL && pFOParam->pFileData!= NULL ) { for(i=0; i < pFOParam->nNumOfFiles; ++i ) { if(pFOParam->pFileData[i].pBitmap != NULL) { DumpBitmap.SetHandle(pFOParam->pFileData[i].pBitmap); DumpBitmap.Free(); GlobalFreePtr(pFOParam->pFileData[i].pBitmap); } if(pFOParam->pFileData[i].pThumbnail != NULL) { DumpBitmap.SetHandle(pFOParam->pFileData[i].pThumbnail); DumpBitmap.Free(); 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; } } /*--------------------------------------------------------------------------+ | Function :OnFileOpen | Desc :open a file | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCApp::OnFileOpen() { L_INT nRet; HWND hWndChild = NULL; OPENFILENAME OpenFileName; L_TCHAR szFileTitle[_MAX_PATH]=TEXT(""); OPENDLGPARAMS FOParm; L_TCHAR szFilter[] = TEXT("All Files (*.*)\0*.*\0") TEXT("\0"); memset(&FOParm, 0, sizeof(OPENDLGPARAMS)); FOParm.uStructSize = sizeof(OPENDLGPARAMS); FOParm.uDlgFlags = DLG_OPEN_SHOW_MULTIPAGE | DLG_OPEN_SHOW_FILEINFO | DLG_OPEN_SHOW_PREVIEW | DLG_OPEN_VIEWTOTALPAGES ; FOParm.bPreviewEnabled = TRUE; memset(&OpenFileName,0,sizeof(OpenFileName)); OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.hwndOwner = NULL; OpenFileName.lpstrFilter = szFilter; OpenFileName.lpstrCustomFilter = NULL; OpenFileName.nMaxCustFilter = 0; OpenFileName.nFilterIndex = 0; OpenFileName.lpstrFileTitle = szFileTitle; OpenFileName.nMaxFileTitle = sizeof(szFileTitle); OpenFileName.lpstrInitialDir = NULL; OpenFileName.lpstrTitle = TEXT("Open a File"); OpenFileName.nFileOffset = 0; OpenFileName.nFileExtension = 0; OpenFileName.lpstrDefExt = NULL; OpenFileName.Flags = 0; #if(WINVER >= 0x0400) OpenFileName.Flags |= OFN_ENABLESIZING; #endif /* WINVER >= 0x0400 */ LDialogFile DlgFile; DlgFile.SetOpenFileName( &OpenFileName); DlgFile.SetOpenParams( &FOParm); nRet = DlgFile.DoModalOpen(m_pMainWnd->m_hWnd); DlgFile.GetOpenFileName( &OpenFileName); DlgFile.GetOpenParams( &FOParm,sizeof(FOParm)); if( nRet == SUCCESS_DLG_OK ) { m_nPageNumber = FOParm.pFileData[0].nPageNumber; OpenDocumentFile( (LPCTSTR)FOParm.pFileData[0].szFileName ); CleanOpenDlgParam(&FOParm); } else { if(nRet != SUCCESS_DLG_CANCEL) theApp.DisplayLEADError(nRet); } } /*--------------------------------------------------------------------------+ | Function :OpenDocumentFile | Desc :open a document file | Return :CDocument* | Notes : +--------------------------------------------------------------------------*/ CDocument* CABCApp::OpenDocumentFile( LPCTSTR lpszFileName ) { m_Quality = -1; lstrcpy( m_szQuality, TEXT("") ); CloseAllDocuments( FALSE ); lstrcpy( m_szOpenedFileName, lpszFileName ); CABCDoc *pDoc = (CABCDoc*)CWinApp::OpenDocumentFile( m_szOpenedFileName ); if( pDoc ) { CString csTitle = pDoc->GetTitle(); csTitle += " (Original)"; pDoc->SetTitle( csTitle ); } return pDoc; } /*--------------------------------------------------------------------------+ | Function :DisplayLEADError | Desc :Display an error message | Return :int | Notes : +--------------------------------------------------------------------------*/ int CABCApp::DisplayLEADError(int nCode) { CString cs; if(nCode != SUCCESS) { cs.Format(TEXT("A LEADTOOLS error has occured.\nCODE = %d"), nCode); m_pMainWnd->MessageBox(cs, TEXT("Error"), MB_OK|MB_ICONERROR); } return(nCode); } /*--------------------------------------------------------------------------+ | Function :SetDisplayMode | Desc :Set the display mode | Return :DWORD | Notes : +--------------------------------------------------------------------------*/ DWORD CABCApp::SetDisplayMode(void) { DWORD dwFlags; dwFlags = LBitmapSettings::GetDisplayMode(); LBitmapSettings::SetDisplayMode( DISPLAYMODE_SCALETOGRAY | DISPLAYMODE_FAVORBLACK, m_nDisplayMode ) ; return dwFlags; } /*--------------------------------------------------------------------------+ | Function :FitImagesToWindows | Desc :fit image to window | Return :bool | Notes : +--------------------------------------------------------------------------*/ BOOL CABCApp::FitImagesToWindows( ) { POSITION pos = GetFirstDocTemplatePosition(); while( pos ) { CDocTemplate* pTemplate = (CDocTemplate*)GetNextDocTemplate(pos); POSITION pos2 = pTemplate->GetFirstDocPosition(); while( pos2 != NULL ) { CDocument* pDoc = pTemplate->GetNextDoc(pos2); POSITION pos = pDoc->GetFirstViewPosition(); CABCView* pFirstView = (CABCView*)pDoc->GetNextView( pos ); pFirstView->Fitimagetowindow(); } } return FALSE; } /*--------------------------------------------------------------------------+ | Function :ClosePreviewDocument | Desc :close the preview window | Return :bool | Notes : +--------------------------------------------------------------------------*/ BOOL CABCApp::ClosePreviewDocument( ) { POSITION pos = GetFirstDocTemplatePosition(); while( pos ) { CDocTemplate* pTemplate = (CDocTemplate*)GetNextDocTemplate(pos); POSITION pos2 = pTemplate->GetFirstDocPosition(); while( pos2 != NULL ) { CDocument* pDoc = pTemplate->GetNextDoc(pos2); CString sTitle = pDoc->GetTitle(); CString sPT = sTitle.Left( sizeof(PREVIEWSTRING)-1 ); CString sPV(PREVIEWSTRING); if( !sPT.Compare(sPV) ) pDoc->OnCloseDocument(); } } return FALSE; } /*--------------------------------------------------------------------------+ | Function :AddToRecentFileList | Desc :we have overridden this function only to remove previous file name from recent file list | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCApp::AddToRecentFileList( LPCTSTR lpszPathName ) { // if the file name is not the preview file name save it to recent list... if( lstrcmp( lpszPathName, PREVIEW_TEMP_FILE_NAME) ) CWinApp::AddToRecentFileList( lpszPathName ); }