MFC static text 设置背景透明失败

cahnghui3067 2015-02-01 10:07:11
我在VC里写MFC的时候,在类的消息WM_CTLCOLOR中用了下面的代码设置static text控件的背景透明:
if(nCtlColor == CTLCOLOR_STATIC)
{
pDC-> SetBkMode( TRANSPARENT );
}
但是运行的结果是文字背景为基础的灰色,而不是和对话框的背景图一致的颜色,请问有谁遇到过这样的问题吗?有什么解决办法吗?
...全文
1350 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dear王二小 2015-12-26
  • 打赏
  • 举报
回复
我也是这个问题,如何改啊????
cahnghui3067 2015-02-02
  • 打赏
  • 举报
回复
引用 2 楼 lsq19871207 的回复:

HBRUSH Cxxx::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
     if(nCtlColor == CTLCOLOR_STATIC)
     {
		 pDC->SetBkMode(TRANSPARENT);
		 //CWnd* pStatic = GetDlgItem(IDC_XXXXX);
		 //if(pWnd->m_hWnd == pStatic->m_hWnd)
		 //{			
		 //	 pDC->SetTextColor ( RGB(0,0,255) );
		 //}

		 return   (HBRUSH)::GetStockObject(NULL_BRUSH);   
     }
     return CxxxParent::OnCtlColor(pDC,   pWnd,   nCtlColor);;
}
非常感谢,就是那个reuturn的问题
cahnghui3067 2015-02-02
  • 打赏
  • 举报
回复
引用 3 楼 sj19890401 的回复:
需要返回透明画刷 return (HBRUSH)::GetStockObject(NULL_BRUSH);
谢谢了,的确是这样。
一朵格桑花 2015-02-02
  • 打赏
  • 举报
回复
需要返回透明画刷 return (HBRUSH)::GetStockObject(NULL_BRUSH);
信阳毛尖 2015-02-02
  • 打赏
  • 举报
回复

HBRUSH Cxxx::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
     if(nCtlColor == CTLCOLOR_STATIC)
     {
		 pDC->SetBkMode(TRANSPARENT);
		 //CWnd* pStatic = GetDlgItem(IDC_XXXXX);
		 //if(pWnd->m_hWnd == pStatic->m_hWnd)
		 //{			
		 //	 pDC->SetTextColor ( RGB(0,0,255) );
		 //}

		 return   (HBRUSH)::GetStockObject(NULL_BRUSH);   
     }
     return CxxxParent::OnCtlColor(pDC,   pWnd,   nCtlColor);;
}
寒沙胜雪 2015-02-01
  • 打赏
  • 举报
回复
HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { // Call the base class implementation first! Otherwise, it may // undo what we're trying to accomplish here. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // Are we painting the IDC_MYSTATIC control? We can use // CWnd::GetDlgCtrlID() to perform the most efficient test. if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC) { // Set the text color to red pDC->SetTextColor(RGB(255, 0, 0)); // Set the background mode for text to transparent // so background will show thru. pDC->SetBkMode(TRANSPARENT); // Return handle to our CBrush object hbr = m_brush; } return hbr; } 试试用控件ID行不

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧