Bitmap Button 不可用的情况

本文探讨了如何在CButtonST类中实现当按钮不可用时仅将Bitmap灰化的效果,而非显示为灰色框。提供了具体的代码片段以帮助理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

根据CButtonST类写了一个可以加载Bitmap 、Icon的按钮

但是缺陷是设置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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值