www.pudn.com > pngButton(GDI+).rar > Picture.cpp
// Picture.cpp : implementation file
//
#include "stdafx.h"
#include "pngButtonMaker.h"
#include "Picture.h"
#include ".\picture.h"
// CPicture
IMPLEMENT_DYNAMIC(CPicture, CStatic)
CPicture::CPicture()
{
//image=new Bitmap(L"123.PNG");
m_IsImage=false;
}
CPicture::~CPicture()
{
}
BEGIN_MESSAGE_MAP(CPicture, CStatic)
ON_WM_PAINT()
END_MESSAGE_MAP()
// CPicture message handlers
void CPicture::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
Graphics graphics(dc.m_hDC);
if (m_IsImage != false)
{
GetClientRect(&m_rect);
try
{
graphics.DrawImage(image,Rect(m_rect.left,m_rect.top,m_rect.Width(),m_rect.Height()));
}
catch (CException* e)
{
MessageBox("something wrong!");
}
//graphics.DrawImage(image,Rect(m_rect.left,m_rect.top,m_rect.Width(),m_rect.Height()));
}
// Do not call CStatic::OnPaint() for painting messages
}
void CPicture::SetImage(WCHAR* path)
{
image = Image::FromFile(path,true);
m_IsImage = true;
Invalidate();
}
void CPicture::SetImage(Image &bmp)
{
//image=Image::Clone(bmp);
//image=&bmp;
image = bmp.Clone();
m_IsImage = true;
Invalidate();
}