我有个对话框程序,背景是一幅图,上面有个静态文本框(CStatic), 想实现文本框的背景是透明的,
但隔一段时间改变文字内容,我已经实现透明功能,但当我改变文字内容时,旧的未能消去,
新的覆盖在就文字上面。
透明功能通过给对话框类添加以下消息函数实现:
HBRUSH CCColorStaticST_demoDlg::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)//对话框:CTLCOLOR_DLG 按钮:CTLCOLOR_BTN 
               {
                     pDC->SetBkMode(TRANSPARENT); //设置背景透明
                     return HBRUSH(GetStockObject(HOLLOW_BRUSH));
               }                             return hbr;
// TODO: Return a different brush if the default is not desired
return hbr;
}
我用以下函数测试,最后结果是乱七八糟的一堆,重叠在一起,
而不是我期望的依次显示aaaa,bbbbbbbb,cccccccccccccvoid CCColorStaticST_demoDlg::OnButton1() 
{
// TODO: Add your control notification handler code here m_cstrStaticMy = "aaaa";    // 定义: CStatic m_cstrStaticMy 
UpdateData(FALSE); Sleep(1000); m_cstrStaticMy = "bbbbbbbb";
UpdateData(FALSE); Sleep(1000); m_cstrStaticMy = "cccccccccccc";
UpdateData(FALSE);
}
请大家帮我!非常感谢!

解决方案 »

  1.   

    你的CSTATIC的ID是什么!不能用默认的!
      

  2.   

    我试了一下,可以的!先不要用默认的IDreturn HBRUSH(GetStockObject(HOLLOW_BRUSH));//不要用HOLLOW返回空画刷,
      

  3.   

    换一个
    return HBRUSH(GetStockObject(WHITE_BRUSH));//你可以把sleep的时间改长点来观察效果!
      

  4.   

    laiyiling(最熟悉的陌生人) , 您好!我的CStatic 的ID 不是用默认的,我另起了另外如果换成return HBRUSH(GetStockObject(WHITE_BRUSH));
    静态文本框的背景又变得不透明了,反而在我的图片上出现了一块方形灰影.
      

  5.   

    改为return HBRUSH(GetStockObject(WHITE_BRUSH));//
      

  6.   

    HBRUSH CTest6Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); switch(nCtlColor)
    {
    case CTLCOLOR_DLG:
    static HBRUSH hbrdlg = ::CreateSolidBrush( RGB(255, 255, 255) );
    pDC->SetBkColor(TRANSPARENT);
    return hbrdlg;
    } // TODO: Return a different brush if the default is not desired
    return hbr;
    }
      

  7.   

    HBRUSH CTest6Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); switch(nCtlColor)
    {
    case CTLCOLOR_DLG:
    static HBRUSH hbrdlg = ::CreateSolidBrush( RGB(255, 255, 255) );
    pDC->SetBkColor(TRANSPARENT);
    return hbrdlg;
    } // TODO: Return a different brush if the default is not desired
    return hbr;
    }
      

  8.   

    HBRUSH CTest6Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); switch(nCtlColor)
    {
    case CTLCOLOR_DLG:
    static HBRUSH hbrdlg = ::CreateSolidBrush( RGB(255, 255, 255) );
    pDC->SetBkColor(TRANSPARENT);
    return hbrdlg;
    } // TODO: Return a different brush if the default is not desired
    return hbr;
    }