45 lines
881 B
C++
45 lines
881 B
C++
#include "stdafx.h"
|
|
#include "CImageShowStatic.h"
|
|
|
|
IMPLEMENT_DYNAMIC(CImageShowStatic, CStatic)
|
|
|
|
CImageShowStatic::CImageShowStatic()
|
|
{
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CImageShowStatic, CStatic)
|
|
//ON_WM_PAINT()
|
|
END_MESSAGE_MAP()
|
|
|
|
void CImageShowStatic::PreSubclassWindow()
|
|
{
|
|
CStatic::PreSubclassWindow();
|
|
ModifyStyle(0, SS_OWNERDRAW);
|
|
}
|
|
|
|
void CImageShowStatic::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
|
|
{
|
|
CDC* pDc = CDC::FromHandle(lpDrawItemStruct->hDC);
|
|
CRect rect = lpDrawItemStruct->rcItem;
|
|
|
|
CImage image;
|
|
|
|
if (FAILED(image.Load(m_sJPGFile)))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//获取控件的矩形
|
|
CRect rectControl;
|
|
GetWindowRect(&rectControl);
|
|
ScreenToClient(rectControl);
|
|
|
|
//以控件为画布,在其上画图
|
|
SetStretchBltMode(pDc->m_hDC, STRETCH_HALFTONE);
|
|
|
|
//画图(以下两种方法都可)
|
|
//image.StretchBlt(pDc->m_hDC, rectPicture, SRCCOPY);
|
|
image.Draw(pDc->m_hDC, rectControl);
|
|
|
|
image.Destroy();
|
|
} |