如何在MFC应用程序中使按钮背景透明? [英] How do I make a button background transparent in MFC application?

查看:741
本文介绍了如何在MFC应用程序中使按钮背景透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除复选框文本的标准背景颜色以及我的groupbox标题。有谁知道如何在MFC应用程序中解决这个问题?



我目前正在尝试使用CTLCOLOR,但我似乎无法让它工作。



先谢谢了,

:]

I need to remove the standard background color of my checkbox text as well as my groupbox captions. Does anyone know how to go about this in MFC application?

I'm currently trying to work with CTLCOLOR but I can't seem to get it to work.

Thanks in Advance,
:]

推荐答案

我认为这个方式:





ON_WM_ERASEBKGND()



BOOL CMyDialog :: OnEraseBkgnd(CDC * pDC)

{

CRect r;

GetClientRect(& r);

if((HBRUSH)m_brush == NULL)

m_brush.CreateSolidBrush(RGB(100,100,100));

pDC-> FillRect (& r,& m_brush);

返回TRUE;

}



ON_WM_CTLCOLOR ()



HBRUSH CMyDialog :: OnCtlColor(CDC * pDC,CWnd * pWnd,UINT nCtlColor)

{

HBRUSH hbr = CDialog :: OnCtlColor(pDC,pWnd,nCtlColor);



TCHAR classname [MAX_PATH];

if(:: GetClassName(pWnd-> m_hWnd,classna我,MAX_PATH)== 0)

返回hbr;

if(_tcsicmp(classname,_T(EDIT))== 0)

return hbr;

if(_tcsicmp(classname,_T(COMBOBOX))== 0)

return hbr;

if (_tcsicmp(classname,_T(COMBOLBOX))== 0)

return hbr;

if(_tcsicmp(classname,_T(LISTBOX))== 0)

返回hbr;

if(_tcsicmp(classname,WC_TREEVIEW)== 0)

return hbr;





pDC-> SetBkColor(RGB(100,100,100));



if((HBRUSH)m_brush == NULL)

m_brush.CreateSolidBrush(RGB(192,192,192));

return(HBRUSH)m_brush;

}
I figured it this way:


ON_WM_ERASEBKGND()

BOOL CMyDialog::OnEraseBkgnd(CDC* pDC)
{
CRect r;
GetClientRect(&r);
if ((HBRUSH)m_brush == NULL)
m_brush.CreateSolidBrush(RGB(100, 100, 100));
pDC->FillRect(&r, &m_brush);
return TRUE;
}

ON_WM_CTLCOLOR()

HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

TCHAR classname[MAX_PATH];
if (::GetClassName(pWnd->m_hWnd, classname, MAX_PATH) == 0)
return hbr;
if (_tcsicmp(classname, _T("EDIT")) == 0)
return hbr;
if (_tcsicmp(classname, _T("COMBOBOX")) == 0)
return hbr;
if (_tcsicmp(classname, _T("COMBOLBOX")) == 0)
return hbr;
if (_tcsicmp(classname, _T("LISTBOX")) == 0)
return hbr;
if (_tcsicmp(classname, WC_TREEVIEW) == 0)
return hbr;


pDC->SetBkColor(RGB(100, 100, 100));

if ((HBRUSH)m_brush == NULL)
m_brush.CreateSolidBrush(RGB(192, 192, 192));
return (HBRUSH)m_brush;
}


这篇关于如何在MFC应用程序中使按钮背景透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆