IMAGEVIEWDOC.CPP
上传用户:alisonmail
上传日期:2013-02-28
资源大小:500k
文件大小:4k
- // ImageViewDoc.cpp : implementation of the CImageViewDoc class
- //
- #include "stdafx.h"
- #include "ImageView.h"
- #include "ImageViewDoc.h"
- #include "ImageViewView.h"
- #include "MainFrm.h"
- #include "ChildFrm.h"
- #include "Brightness.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CImageViewDoc
- IMPLEMENT_DYNCREATE(CImageViewDoc, CDocument)
- BEGIN_MESSAGE_MAP(CImageViewDoc, CDocument)
- //{{AFX_MSG_MAP(CImageViewDoc)
- ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CImageViewDoc construction/destruction
- CImageViewDoc::CImageViewDoc()
- {
- // TODO: add one-time construction code here
- }
- CImageViewDoc::~CImageViewDoc()
- {
- }
- BOOL CImageViewDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CImageViewDoc serialization
- void CImageViewDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CImageViewDoc diagnostics
- #ifdef _DEBUG
- void CImageViewDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CImageViewDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CImageViewDoc commands
- void CImageViewDoc::OnFileSaveAs()
- {
- static int nIndex = 1;
- char szFilter[] = "BMP Files(*.BMP)|*.BMP|GIF Files(*.GIF)|*.GIF|PCX Files(*.PCX)|*.PCX|Targa Files(*.TGA)|*.TGA|Jpeg Files(*.JPG)|*.JPG|Tif Files(*.TIF)|*.TIF||";
- CFileDialog FileDlg( FALSE, NULL, NULL, OFN_HIDEREADONLY, szFilter );
- FileDlg.m_ofn.nFilterIndex = (DWORD) nIndex;
- if( FileDlg.DoModal() == IDOK ){
- nIndex = (int) FileDlg.m_ofn.nFilterIndex;
- CMainFrame *pFrame = (CMainFrame *) AfxGetMainWnd();
- CChildFrame *pChild = (CChildFrame *) pFrame->MDIGetActive();
- CImageViewView *pView = (CImageViewView *) pChild->GetActiveView();
- if( nIndex == 5 ){
- if( pView->m_pImageObject->GetNumBits() != 24 ){
- AfxMessageBox( "The image must be 24 bits of color resolution to save as JPEG" );
- return;
- }
- CBrightness Brightness;
- strcpy( Brightness.m_szTitle, "Set Quality" );
- strcpy( Brightness.m_szLabel, "Quality" );
- if( Brightness.DoModal() != IDOK ) return;
- if( pView->m_pImageObject != NULL )
- pView->m_pImageObject->SetQuality( Brightness.m_nBrightness / 2 );
- }
- if( pView->m_pImageObject != NULL ){
- CString PathName = FileDlg.GetPathName();
- int nFindIndex = PathName.Find( "." );
- if( nFindIndex != -1 ) PathName = PathName.Left( nFindIndex );
- PathName += CImageObject::szExtensions[nIndex-1];
- pView->m_pImageObject->Save( PathName );
- CString FileName = FileDlg.GetFileName();
- nFindIndex = FileName.Find( "." );
- if( nFindIndex != -1 ) FileName = FileName.Left( nFindIndex );
- FileName += CImageObject::szExtensions[nIndex-1];
- FileName.MakeUpper();
- pChild->SetWindowText( FileName );
- SetPathName( PathName );
- if( nIndex == 5 ){
- pView->m_pImageObject->Load( PathName );
- pView->InvalidateRect( NULL, FALSE );
- pView->UpdateWindow();
- }
- }
- }
- }