VC中设置STATIC控件背景,比如透明

 

假设static控件ID为IDC_STATIC1: 
然后重载对话框的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; 
}

 

需要注意的是,在VC的Control界面中,必须将STATIC属性Simple选中,否则pWnd->GetDlgCtrlID()找不到关于STATIC的任何控件。

另外,BTN不能用OnCtlColor去改变颜色,会没有作用;CHECK_BOX也属于Button一类。可以考虑文字部分用Static Text去做。

posted @ 2013-06-24 22:05  freedom_sure  阅读(666)  评论(0编辑  收藏  举报