在一幅背景图片上放一个CStatic控件,此控件用来动态显示当前时间,怎么能够让这个
CStatic控件背景透明那?

解决方案 »

  1.   

    我做了一个类,其中
    void CColorStatic::OnPaint() 
    {
    CPaintDC dc(this); // device context for painting

    // TODO: Add your message handler code here
    CRect rect;
    GetClientRect(&rect);
    dc.SetBkColor(m_BackColor);
    dc.SetBkMode(TRANSPARENT);
    CFont *pFont=GetParent()->GetFont();
    CFont* pOldFont;
    pOldFont=dc.SelectObject(pFont);
        dc.SetTextColor(m_TextColor); dc.DrawText(m_strCaption,&rect,DT_CENTER);
    dc.SelectObject(pOldFont);
    // Do not call CStatic::OnPaint() for painting messages
    }但是在使用时,
    CColorStatic m_Timer;
    m_Timer.SubclassDlgItem(IDC_TIMER,this);
    void CNetServerDlg::OnTimer(UINT nIDEvent) 
    {
    // TODO: Add your message handler code here and/or call default
    if(nIDEvent==TIMER_SHOW)
    {
            CTime _time;
    CString m_time;
    _time=CTime::GetCurrentTime();
    m_time=_time.Format("%H:%M:%S");
    SetDlgItemText(IDC_TIMER,m_time);
    /*m_Timer.SetCaption(m_time);
    m_Timer.SetTextColor(RGB(0,0,255));*/
    }
    CDialog::OnTimer(nIDEvent);
    }
    在Timer中就显示不出来,如果不在Timer中就可以,例如
    m_Timer.SetCaption("测试");
    m_Timer.SetTextColor(RGB(0,0,255));
      

  2.   

    我写的扩展CStatic类,响应它的=WM_CTRCOLOR消息就行了:
    HBRUSH CExStatic::CtlColor(CDC* pDC, UINT nCtlColor) 
    {
    // TODO: Change any attributes of the DC here
    pDC->SetTextColor( RGB(255,0,0) );
    pDC->SetBkMode(TRANSPARENT);
    return((HBRUSH)GetStockObject(NULL_BRUSH));
    }
    然后生成一个CExStatic变量就行了
      

  3.   

    edoch(逸刀客):不行的!
    还是刷新显示不出来
      

  4.   

    怎么会呢,给我个E-mail.我把代码发给你
      

  5.   

    m_Timer.SubclassDlgItem(IDC_TIMER,this);
    这句话执行后就一直在OnPaint中执行,所以strCaption和颜色等都没有赋值进去那,所以没有显示出来,但是我如果不加时钟,直接
    m_Timer.SubclassDlgItem(IDC_TIMER,this);
    //this->SetTimer(TIMER_SHOW,1000,0);
    m_Timer.SetCaption("测试");
    m_Timer.SetTextColor(RGB(0,0,255));
    就可以显示"测试"两字,是什么原因?
    我现在是在
    Ontimer中
    if(nIDEvent==TIMER_SHOW)
    {
            CTime _time;
    CString m_time;
    _time=CTime::GetCurrentTime();
    m_time=_time.Format("%H:%M:%S");
    //SetDlgItemText(IDC_TIMER,m_time);
    m_Timer.SetCaption(m_time);
    m_Timer.SetTextColor(RGB(0,0,255));
    }
      

  6.   

    画控件的时候,先取得背景每个点的RGB值,然后乘一个比例因子,作为前景的控件的RGB值,这样就能实现半透明了。
    记得有个AlphaBlend直接实现alpha效果,但是只能画位图。
      

  7.   

    edoch(逸刀客)的方法的确好用!