// RstDemo.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "RstDemo.h" #include "MainFrm.h" #include "ChildFrm.h" #include "RstDoc.h" #include "RstView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRstDemoApp BEGIN_MESSAGE_MAP(CRstDemoApp, CWinApp) //{{AFX_MSG_MAP(CRstDemoApp) 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() ///////////////////////////////////////////////////////////////////////////// // CRstDemoApp construction CRstDemoApp::CRstDemoApp() { LBase::LoadLibraries(LT_PDG|LT_KRN|LT_FIL|LT_DLG|LT_AUT|LT_CON|LT_TLB|LT_DIS); WRPUNLOCKSUPPORT(); LDialogBase::Initialize(DLG_INIT_COLOR); LBase::SetErrorListDepth(100); } CRstDemoApp::~CRstDemoApp() { FreeImages(); LDialogBase::Free(); LBase::UnloadLibraries(LT_PDG|LT_KRN|LT_FIL|LT_DLG|LT_AUT|LT_CON|LT_TLB|LT_DIS); } ///////////////////////////////////////////////////////////////////////////// // The one and only CRstDemoApp object CRstDemoApp theApp; ///////////////////////////////////////////////////////////////////////////// // CRstDemoApp initialization BOOL CRstDemoApp::InitInstance() { // 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. // You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("Lead Technologies-RasterPaint Demo Application")); 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_RSTDEMTYPE, RUNTIME_CLASS(CRstDemoDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CRstDemoView)); 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); cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; // 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(); LoadImages(); 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 CRstDemoApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CRstDemoApp commands BOOL CRstDemoApp::InitApplication() { return CWinApp::InitApplication(); } void CRstDemoApp::OnFileOpen() { OPENDLGPARAMS FOParm ; OPENFILENAME OpenFileName; memset ( &FOParm, 0, sizeof(OPENDLGPARAMS)) ; memset ( &OpenFileName, 0, sizeof(OPENFILENAME)) ; OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.lpstrInitialDir = NULL; OpenFileName.Flags = OFN_EXPLORER; FOParm.uStructSize = sizeof(OPENDLGPARAMS); FOParm.uDlgFlags = DLG_OPEN_ENABLESIZING | DLG_OPEN_SHOW_PROGRESSIVE | DLG_OPEN_USEFILESTAMP | DLG_OPEN_SHOW_MULTIPAGE | DLG_OPEN_SHOW_LOADROTATED | DLG_OPEN_SHOW_LOADCOMPRESSED | DLG_OPEN_SHOW_DELPAGE | DLG_OPEN_SHOW_LOADOPTIONS | DLG_OPEN_SHOW_FILEINFO | DLG_OPEN_SHOW_PDFOPTIONS | DLG_OPEN_SHOW_RASTEROPTIONS | DLG_OPEN_SHOW_VECTOROPTIONS | DLG_OPEN_VIEWTOTALPAGES; FOParm.bPreviewEnabled = TRUE; m_LBitmap.DialogFile()->SetOpenParams(&FOParm) ; m_LBitmap.DialogFile()->EnablePreview(TRUE); m_LBitmap.DialogFile()->SetOpenFileName(&OpenFileName) ; m_LBitmap.DialogFile()->EnableCallBack(FALSE); L_INT nRetCode = m_LBitmap.DialogFile()->DoModalOpen(m_pMainWnd->m_hWnd); if(nRetCode==SUCCESS_DLG_OK) { L_TCHAR szFileName[256]; memset(szFileName,0,sizeof(szFileName)); L_UINT uSize=sizeof(szFileName); m_LBitmap.GetFileName(szFileName,&uSize); m_LBitmap.DialogFile()->GetOpenParams(&FOParm,sizeof(FOParm)) ; POSITION pos = GetFirstDocTemplatePosition(); CDocTemplate* pDocTemplate = GetNextDocTemplate(pos); pDocTemplate->OpenDocumentFile(szFileName); } } void CRstDemoApp::LoadImages() { DIBSECTION dibsc; BITMAPHANDLE TempBtmapHandle; // load background tile image. HANDLE hBitmap = ::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BACK_TILE), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE); GetObject(hBitmap , sizeof (DIBSECTION), &dibsc); L_CONVERTFROMDIB(&TempBtmapHandle, sizeof(BITMAPHANDLE),(LPBITMAPINFO) &dibsc.dsBmih, (L_UCHAR*)dibsc.dsBm.bmBits); m_LBtmpBackTile.SetHandle(&TempBtmapHandle); m_LBtmpBackTile.ChangeViewPerspective(TOP_LEFT); DeleteObject((HBITMAP) hBitmap); // load paper texture image. hBitmap = LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_PAPER_TEXTURE), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE); GetObject(hBitmap , sizeof (DIBSECTION), &dibsc); L_CONVERTFROMDIB(&TempBtmapHandle, sizeof(BITMAPHANDLE),(LPBITMAPINFO) &dibsc.dsBmih, (L_UCHAR*)dibsc.dsBm.bmBits); m_LBtmpPaperTexture.SetHandle(&TempBtmapHandle); m_LBtmpPaperTexture.ChangeViewPerspective(TOP_LEFT); DeleteObject((HBITMAP) hBitmap); hBitmap = LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP_BRUSH), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE); GetObject(hBitmap , sizeof (DIBSECTION), &dibsc); L_CONVERTFROMDIB(&TempBtmapHandle, sizeof(BITMAPHANDLE) ,(LPBITMAPINFO) &dibsc.dsBmih, (L_UCHAR *)dibsc.dsBm.bmBits); m_LBtmpBrush.SetHandle(&TempBtmapHandle); m_LBtmpBrush.ChangeViewPerspective(TOP_LEFT); DeleteObject((HBITMAP) hBitmap); m_hBorderTile = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BORDER_TILE)); } void CRstDemoApp::FreeImages() { if(m_hBorderTile != NULL) DeleteObject(m_hBorderTile); m_LBtmpBackTile.Free(); m_LBtmpBrush.Free(); m_LBtmpPaperTexture.Free(); } int CRstDemoApp::ExitInstance() { return CWinApp::ExitInstance(); } void CRstDemoApp::DoSaveAllDocs() { CObList pDocList; POSITION pos = GetFirstDocTemplatePosition(); while(pos) { CDocTemplate* pTemplate = GetNextDocTemplate(pos); POSITION pos2 = pTemplate->GetFirstDocPosition(); while(pos2) { CDocument* pDocument; if(pDocument = pTemplate->GetNextDoc(pos2)) pDocList.AddHead(pDocument); } } if(!pDocList.IsEmpty()) { pos = pDocList.GetHeadPosition(); while(pos) { CRstDemoDoc* pDocument = (CRstDemoDoc*)pDocList.GetNext(pos) ; pDocument->m_bSaveDocument = FALSE ; POSITION pos = pDocument->GetFirstViewPosition(); CRstDemoView* pView = (CRstDemoView*) pDocument->GetNextView(pos); if( pView ) { 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); } } } } }