关于VC对话框静态文本设置背景透明的问题静态文本设置字体可以
但是设置背景透明显示不可以我在对话框前面又加了一个窗体,用于在这个窗体上显示视频,并将其设置到Z轴最下面
这样,静态文本是在窗体上面,并如下设置HBRUSH CTransstaDlg::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)
{
pDC->SetTextColor(RGB(255, 0, 0));
pDC->SetBkMode(TRANSPARENT);
}// TODO: Return a different brush if the default is not desired
return hbr;
}但是静态文本背景并不是透明的,这是为什么啊?
代码:http://download.csdn.net/detail/yanhc519/4523989谢谢了!

解决方案 »

  1.   

    用MFC ClassWizard添加WM_CTLCOLOR消息:
    HBRUSH CSerialTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) {       HBRUSH hbr= CDialog::OnCtlColor(pDC, pWnd, nCtlColor);              // TODO: Change any attributes of the DC here              // TODO: Return a different brush if the default is not desired       switch(nCtlColor)       {              case CTLCOLOR_STATIC: //对所有静态文本控件的设置              {                     pDC->SetBkMode(TRANSPARENT);//设置背景为透明                                 pDC->SetTextColor(RGB(0,0,0)); //设置字体颜色                     return HBRUSH(GetStockObject(HOLLOW_BRUSH)); // 必须              }              case CTLCOLOR_DLG: //对所有静态文本控件的设置              {                     pDC->SetBkMode(TRANSPARENT);                      return hbr; //返回画刷句柄              }              default:              return CDialog::OnCtlColor(pDC,pWnd, nCtlColor);       }       return hbr;}
      

  2.   

    谢谢你的回复!
    大概明白了点,呵呵
    http://blog.csdn.net/yanhc519/article/details/7905565
    既然设置了参数就应该透明了啊,但是没有传回空的刷子(NULL_BRUSH),所以还是不行。不过,这里有个地方还是想不通,设置透明和传回空的刷子这两个条件都必须要吗?这两者又是什么关系呢?
    我试过,吧设置透明那句注释掉,也不行,所以,两个条件都必须要,但是,为什么呢?