www.pudn.com > dip_1_1_bmp2jpeg.rar > dip_1_1Doc.cpp


// dip_1_1Doc.cpp : implementation of the CDip_1_1Doc class 
// 
 
#include "stdafx.h" 
#include "dip_1_1.h" 
#include "bmp2jpeg.h" 
#include "dip_1_1Doc.h" 
//#include "dip_1_1View.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CDip_1_1Doc 
 
IMPLEMENT_DYNCREATE(CDip_1_1Doc, CDocument) 
 
BEGIN_MESSAGE_MAP(CDip_1_1Doc, CDocument) 
	//{{AFX_MSG_MAP(CDip_1_1Doc) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CDip_1_1Doc construction/destruction 
 
CDip_1_1Doc::CDip_1_1Doc() 
{ 
	m_iDib= new CImage; 
	m_seDib = new CJpegCtr; 
} 
 
CDip_1_1Doc::~CDip_1_1Doc() 
{ 
	delete m_iDib; 
} 
 
BOOL CDip_1_1Doc::OnNewDocument() 
{ 
	if (!CDocument::OnNewDocument()) 
		return FALSE; 
 
	// TODO: add reinitialization code here 
	// (SDI documents will reuse this document) 
 
	return TRUE; 
} 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CDip_1_1Doc serialization 
 
void CDip_1_1Doc::Serialize(CArchive& ar) 
{ 
	m_iDib->Serialize(ar); 
	 
	if (ar.IsStoring()) 
	{ 
		// TODO: add storing code here 
	} 
	else 
	{ 
		// TODO: add loading code here 
	} 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CDip_1_1Doc diagnostics 
 
#ifdef _DEBUG 
void CDip_1_1Doc::AssertValid() const 
{ 
	CDocument::AssertValid(); 
} 
 
void CDip_1_1Doc::Dump(CDumpContext& dc) const 
{ 
	CDocument::Dump(dc); 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CDip_1_1Doc commands 
 
BOOL CDip_1_1Doc::OnOpenDocument(LPCTSTR lpszPathName)  
{ 
	//CFile file; 
	CFileException fe; 
	//CImage *pImg = new CImage(); 
	 
	CFile* pFile = new CFile(); 
	//CFileException e; 
	//	LPCTSTR file_name = filename; 
	 
	if(!pFile->Open(lpszPathName, CFile::modeRead)) 
	{ 
		AfxMessageBox("In CImage::ReadFromFile(),Can not opent the file!"); 
		return false; 
	} 
	 
 
 
	BOOL b = m_iDib->ReadFromFile(pFile); 
	if (!b)  
	{ 
		return FALSE; 
	} 
 
 
 
 
	pFile->Close(); 
	delete pFile; 
	if(!m_seDib->LoadBmp(lpszPathName)) 
	{ 
		AfxMessageBox("11111111Jpeg compress process failure!"); 
		return false; 
	} 
	DeleteContents(); 
	 
	 
	return TRUE; 
}