本人想设置界面上滑块控件透明,代码如下:
HBRUSH CSliderDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if ( nCtlColor==CTLCOLOR_STATIC||nCtlColor==CTLCOLOR_BTN||pWnd->GetDlgCtrlID()==IDC_SLIDER1)//包括滑块控件ID
{
pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkMode(TRANSPARENT);
pDC->SetBkColor(RGB(255,255,255));
return (HBRUSH)::GetStockObject(NULL_BRUSH);//此处NULL_BRUSH作用为透明画刷,但是除了滑块其他都可以透明;如果改成WHITE_BRUSH则滑块背景不是黑的,但是不透明
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
,效果如图:
图中可以看到static控件已经是透明的了,为什么滑块不能透明?怎么才能让滑块也透明?
------解决方案--------------------
static HBRUSH brush_red = ::CreateSolidBrush(RGB(212,212,212));
if(pWnd->GetDlgCtrlID()==IDC_SLIDER)
{
pDC->SetTextColor(RGB(255,255,255));
pDC->SetBkMode(TRANSPARENT);
CRect rect;
GetDlgItem(IDC_SLIDER_input)->GetWindowRect(rect);
pDC->SetBoundsRect(rect,IDC_SLIDER_input);
return brush_red; //返回的画刷 是填满没字的地方用的
}