控件背景

 
定义类变量:
HBITMAP m_hBackGroundBmp; //背景

增加下面的接口:
AddBackgroundBmp(BSTR pBmpFile)
{
if(pBmpFile == NULL)
return S_FALSE;
m_hBackGroundBmp = (HBITMAP)::LoadImage(_Module.GetModuleInstance(), (char *)_com_util::ConvertBSTRToString(pBmpFile), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
return S_OK;
}


OnDraw里添加:
BITMAP bm;
GetObject(m_hBackGroundBmp, sizeof(BITMAP), &bm);

HDC hdc = CreateCompatibleDC( hMemDC );
HBITMAP hOld = (HBITMAP)SelectObject( hdc, m_hBackGroundBmp );
::BitBlt(hMemDC, rc.left, rc.top, bm.bmWidth, bm.bmHeight, hdc, 0, 0, SRCCOPY);
::SelectObject(hdc, hOld);
DeleteDC( hdc );

在控件的FinalRelease()函数里销毁资源:
void ::FinalRelease()
{
if(m_hBackGroundBmp != NULL)
DeleteObject(m_hBackGroundBmp);
}

你可能感兴趣的:(image,null)