www.pudn.com > GdiplusTest16.zip > GdiplusTestView.cpp


// GdiplusTestView.cpp : implementation of the CGdiplusTestView class 
// 
 
#include "stdafx.h" 
#include "GdiplusTest.h" 
 
#include "GdiplusTestDoc.h" 
#include "GdiplusTestView.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CGdiplusTestView 
 
IMPLEMENT_DYNCREATE(CGdiplusTestView, CView) 
 
BEGIN_MESSAGE_MAP(CGdiplusTestView, CView) 
	//{{AFX_MSG_MAP(CGdiplusTestView) 
	ON_COMMAND(ID_TOOL_JPG, OnToolJpg) 
	//}}AFX_MSG_MAP 
	// Standard printing commands 
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CGdiplusTestView construction/destruction 
 
CGdiplusTestView::CGdiplusTestView() 
{ 
	// TODO: add construction code here 
 
} 
 
CGdiplusTestView::~CGdiplusTestView() 
{ 
} 
 
BOOL CGdiplusTestView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CGdiplusTestView drawing 
 
void CGdiplusTestView::OnDraw(CDC* pDC) 
{ 
	CGdiplusTestDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
	using namespace Gdiplus;  
	Image* m_pImage1=((CGdiplusTestDoc*)GetDocument())->m_pImage; 
	if (m_pImage1!=NULL) 
	{ 
		Graphics graphics(pDC->m_hDC); 
		graphics.DrawImage(m_pImage1, 0, 0, m_pImage1->GetWidth(), m_pImage1->GetHeight()); 
		graphics.ReleaseHDC(pDC->m_hDC); 
	} 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CGdiplusTestView printing 
 
BOOL CGdiplusTestView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CGdiplusTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CGdiplusTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CGdiplusTestView diagnostics 
 
#ifdef _DEBUG 
void CGdiplusTestView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CGdiplusTestView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CGdiplusTestDoc* CGdiplusTestView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGdiplusTestDoc))); 
	return (CGdiplusTestDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CGdiplusTestView message handlers 
 
void CGdiplusTestView::OnToolJpg()  
{ 
	// TODO: Add your command handler code here 
	CGdiplusTestDoc*  pDoc=(CGdiplusTestDoc*)GetDocument(); 
	 CString filename; 
	 CString sFilter="jpeg文件(*.jpg)|*.jpg|gif文件(*.gif)|*.gif|bmp文件(*.bmp)|*.bmp||";	 
	 CFileDialog dlgOpen(TRUE,0,0,OFN_HIDEREADONLY| 
	        	OFN_FILEMUSTEXIST,(LPCTSTR)sFilter,this); 
	 if (dlgOpen.DoModal()!=IDOK) 
	   return ; 
	 filename=dlgOpen.GetPathName(); 
	if (pDoc->m_pImage) { 
		delete pDoc->m_pImage; 
		pDoc->m_pImage = NULL; 
	} 
	using namespace Gdiplus;  
	USES_CONVERSION; 
	  pDoc->m_pImage = Image::FromFile(A2W((LPCTSTR)filename),FALSE); 
	Invalidate(); 
}