//绘制子项图片
void CTreeCtrlBT::DrawItemImage(CRect rect, HTREEITEM hItem, CDC *pDc /* = NULL */)
{
if ( NULL == pDc)
{
CClientDC dc(this);
pDc = &dc;
}
CImage img;
HRESULT ret = img.Load(_T("C:\\Users\\Administrator\\Desktop\\a123.png"));//此处暂用固定图片
HBITMAP hbitmap = img.Detach();
CBitmap cBitmap;
BITMAP bitmap;
cBitmap.Attach(hbitmap);
cBitmap.GetBitmap(&bitmap);
//pDc->StretchBlt(0,0,800,590,&memdc,0,0,800,590,SRCCOPY);
if ( cBitmap.GetSafeHandle() )
{
CDC tmpdc;
tmpdc.CreateCompatibleDC(pDc);
CBitmap *pOldBitmap = tmpdc.SelectObject(&cBitmap);
int nXOriginDest = 0;
int nYOriginDest = 0;
int nWidthDest = 0;
int hHeightDest = 0;
nXOriginDest = rect.left;// 目标X偏移
nYOriginDest = rect.top+(rect.Height()-13)/2;// 目标Y偏移
nWidthDest = 13;// 目标宽度
hHeightDest = 13;// 目标高度
::TransparentBlt(pDc->m_hDC,nXOriginDest,nYOriginDest,nWidthDest,hHeightDest,
tmpdc.m_hDC,0,0,bitmap.bmWidth,bitmap.bmHeight,RGB(255,255,255));//白色作为透明色
tmpdc.SelectObject(pOldBitmap);
tmpdc.DeleteDC();
}
}
MFC 绘制 PNG 格式图片
最新推荐文章于 2024-03-07 21:06:43 发布