www.pudn.com > imagescale---raw.zip > ImgScaleDoc.cpp


// ImgScaleDoc.cpp : implementation of the CImgScaleDoc class 
// 
 
#include "stdafx.h" 
#include "ImgScale.h" 
 
#include "ImgScaleDoc.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CImgScaleDoc 
 
IMPLEMENT_DYNCREATE(CImgScaleDoc, CDocument) 
 
BEGIN_MESSAGE_MAP(CImgScaleDoc, CDocument) 
	//{{AFX_MSG_MAP(CImgScaleDoc) 
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CImgScaleDoc construction/destruction 
 
CImgScaleDoc::CImgScaleDoc() 
{ 
	// TODO: add one-time construction code here 
	m_pDib = NULL; 
} 
 
CImgScaleDoc::~CImgScaleDoc() 
{ 
	if(m_pDib) delete m_pDib; 
} 
 
BOOL CImgScaleDoc::OnNewDocument() 
{ 
	if (!CDocument::OnNewDocument()) 
		return FALSE; 
 
	// TODO: add reinitialization code here 
	// (SDI documents will reuse this document) 
 
	return TRUE; 
} 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CImgScaleDoc serialization 
 
void CImgScaleDoc::Serialize(CArchive& ar) 
{ 
	if (ar.IsStoring()) 
	{ 
		// TODO: add storing code here 
	} 
	else 
	{ 
		// TODO: add loading code here 
	} 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CImgScaleDoc diagnostics 
 
#ifdef _DEBUG 
void CImgScaleDoc::AssertValid() const 
{ 
	CDocument::AssertValid(); 
} 
 
void CImgScaleDoc::Dump(CDumpContext& dc) const 
{ 
	CDocument::Dump(dc); 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CImgScaleDoc commands 
 
void CImgScaleDoc::OnFileOpen()  
{ 
	// TODO: Add your command handler code here 
	CFileDialog fileOpenDlg(TRUE,"bmp","*.bmp",NULL,"Bitmap Files(*.bmp)",NULL); 
	int nRespond = fileOpenDlg.DoModal(); 
	if(nRespond == IDOK) 
	{ 
		CString filePath = fileOpenDlg.GetPathName(); 
		m_pDib = new CDib(filePath); 
		if(m_pDib->IsValid()) 
			SetTitle(filePath); 
		else	 
			DeleteContents(); 
	} 
	UpdateAllViews(0);		 
} 
 
void CImgScaleDoc::DeleteContents()  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	if (m_pDib) 
    { 
        delete m_pDib; 
        m_pDib = NULL; 
    }	 
	CDocument::DeleteContents(); 
}