根据CButtonST类写了一个可以加载Bitmap 、Icon的按钮
但是缺陷是设置Bitmap按钮为不可用的时候
按钮就变成一个灰色框框
想实现设置Bitmap按钮为不可用的时候 只是让Bitmap变为灰色
这个怎么实现啊
望高手赐教
PS:下面是CButtonST类中重画Bitmap的代码
但是缺陷是设置Bitmap按钮为不可用的时候
按钮就变成一个灰色框框
想实现设置Bitmap按钮为不可用的时候 只是让Bitmap变为灰色
这个怎么实现啊
望高手赐教
PS:下面是CButtonST类中重画Bitmap的代码
void CButtonST::DrawTheBitmap(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled)
{
HDC hdcBmpMem = NULL;
HBITMAP hbmOldBmp = NULL;
HDC hdcMem = NULL;
HBITMAP hbmT = NULL;
BYTE byIndex = 0;
// Select the bitmap to use
if ((m_bIsCheckBox && bIsPressed) || (!m_bIsCheckBox && (bIsPressed || m_bMouseOnButton)))
byIndex = 0;
else
byIndex = (m_csBitmaps[1].hBitmap == NULL ? 0 : 1);
CRect rImage;
PrepareImageRect(bHasTitle, rpItem, rpCaption, bIsPressed, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, &rImage);
hdcBmpMem = ::CreateCompatibleDC(pDC->m_hDC);
hbmOldBmp = (HBITMAP)::SelectObject(hdcBmpMem, m_csBitmaps[byIndex].hBitmap);
hdcMem = ::CreateCompatibleDC(NULL);
hbmT = (HBITMAP)::SelectObject(hdcMem, m_csBitmaps[byIndex].hMask);
if (bIsDisabled && m_bShowDisabledBitmap) //按钮为不可用的时候的处理代码 m_bShowDisabledBitmap为TRUE
{
HDC hDC = NULL;
HBITMAP hBitmap = NULL;
hDC = ::CreateCompatibleDC(pDC->m_hDC);
hBitmap = ::CreateCompatibleBitmap(pDC->m_hDC, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight);
HBITMAP hOldBmp2 = (HBITMAP)::SelectObject(hDC, hBitmap);
RECT rRect;
rRect.left = 0;
rRect.top = 0;
rRect.right = rImage.right + 1;
rRect.bottom = rImage.bottom + 1;
::FillRect(hDC, &rRect, (HBRUSH)RGB(255, 255, 255));
COLORREF crOldColor = ::SetBkColor(hDC, RGB(255,255,255));
::BitBlt(hDC, 0, 0, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcMem, 0, 0, SRCAND);
::BitBlt(hDC, 0, 0, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcBmpMem, 0, 0, SRCPAINT);
::SetBkColor(hDC, crOldColor);
::SelectObject(hDC, hOldBmp2);
::DeleteDC(hDC);
pDC->DrawState( CPoint(rImage.left/*+1*/, rImage.top),
CSize(m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight),
hBitmap, DST_BITMAP | DSS_DISABLED);
::DeleteObject(hBitmap);
} // if
else
{
::BitBlt(pDC->m_hDC, rImage.left, rImage.top, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcMem, 0, 0, SRCAND);
::BitBlt(pDC->m_hDC, rImage.left, rImage.top, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcBmpMem, 0, 0, SRCPAINT);
} // else
::SelectObject(hdcMem, hbmT);
::DeleteDC(hdcMem);
::SelectObject(hdcBmpMem, hbmOldBmp);
::DeleteDC(hdcBmpMem);
} // End of DrawTheBitmap