// PictureEx.cpp : implementation file
//
#include "stdafx.h"
#include "PictureEx.h"
// CPictureEx
IMPLEMENT_DYNAMIC(CPictureEx, CStatic)
CPictureEx::CPictureEx()
{
m_iPicStyle = PICSTYLE_CENTER;
m_colorBkgrnd = m_colorTransparent = RGB(0, 0, 0);
}
CPictureEx::~CPictureEx()
{
}
BEGIN_MESSAGE_MAP(CPictureEx, CStatic)
ON_WM_ERASEBKGND()
ON_WM_PAINT()
END_MESSAGE_MAP()
void CPictureEx::SetTransparentColor(COLORREF color)
{
m_colorTransparent = color;
Invalidate();
}
COLORREF CPictureEx::GetTransparentColor()
{
return m_colorTransparent;
}
void CPictureEx::SetBkColor(COLORREF color)
{
m_colorBkgrnd = color;
Invalidate();
}
COLORREF CPictureEx::GetBkColor()
{
return m_colorBkgrnd;
}
void CPictureEx::SetPictureStyle(INT style)
{
m_iPicStyle = style;
Invalidate();
}
INT CPictureEx::GetPictureStyle()
{
return m_iPicStyle;
}
// CPictureEx message handlers
BOOL CPictureEx::OnEraseBkgnd(CDC* pDC)
{
if(GetBitmap())
{
return TRUE;
}
return CStatic::OnEraseBkgnd(pDC);
}
void CPictureEx::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rClient;
this->GetClientRect(&rClient);
// background
CBrush* br = new CBrush(m_colorBkgrnd);
dc.FillRect(rClient, br);
delete br;
// image
HBITMAP hBmp = this->GetBitmap();
BITMAP bmpObj;
if(hBmp && GetObject(hBmp, sizeof(BITMAP), &bmpObj))
{
INT x, y, w, h;
switch(m_iPicStyle)
{
case PICSTYLE_NORMAL:
x = y = 0;
w = bmpObj.bmWidth;
h = bmpObj.bmHeight;
break;
case PICSTYLE_CENTER:
w = bmpObj.bmWidth;
h = bmpObj.bmHeight;
x = rClient.Width() / 2 - w/2;
y = rClient.Height() / 2 - h/2;
break;
case PICSTYLE_STRETCH:
x = y = 0;
w = rClient.Width();
h = rClient.Height();
break;
}
::TransparentImage(dc, x, y, w, h, hBmp, 0, 0, bmpObj.bmWidth, bmpObj.bmHeight, m_colorTransparent);
}
}
'C & C++ > MFC Media' 카테고리의 다른 글
BMP 투명화 처리 (0) | 2012.11.09 |
---|---|
WM_PAINT 메세지에 대하여... (0) | 2012.10.05 |
BMP, GIF, JPG 수정하기 (0) | 2012.06.20 |
DLL 에 있는 비트맵(Bitmap) 리소스를 실행 파일로 가져오는 방법 3가지 (0) | 2011.12.14 |
Dialog 를 캡쳐하여 인쇄하기 (0) | 2011.10.25 |
댓글