如何让static控件的背景透明?


现在的需求是让这个静态文本背景透明,以显示文本所在背景色,要如何处理?

VC Windows界面开发

不给力啊老师 12 years, 1 month ago

然后重载对话框的WM_CTLCOLOR消息响应函数:

在OnCtlColor中添加如下代码:

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

// TODO: Change any attributes of the DC here
switch(pWnd->GetDlgCtrlID())
{
case IDC_STATIC1:
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0,0,0));
return (HBRUSH)GetStockObject(HOLLOW_BRUSH);
default: break;
}

// TODO: Return a different brush if the default is not desired
return hbr;
}

玫瑰花D葬礼。 answered 12 years, 1 month ago

Your Answer