我自己做了一个按钮类,在其中的DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)中调用一个透明效果处理DrawTransBitmap(....),但是这个按钮显示的时候,只有第一次是正常的透明的,
但是当这个按钮被别的窗口覆盖以后,再还原显示出来的时候,
这个按钮的背景就变成刚刚那个窗口的背景颜色了,不透明了,请问我应该怎么修改呢?
我只在DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)中进行了透明处理,是不是还应该在别的地方也做呢?

解决方案 »

  1.   

    在OnPaint()或者OnEraseBkgnd()事件里还要再写对透明的操作。
      

  2.   

    WM_CTLCOLORBTN:
    SetBkMode((HDC)wParam, TRANSPARENT); 
    return (LONG)GetStockObject(NULL_BRUSH);
      

  3.   

    DrawTransBitmap只画有图形的地方,不画背景,应该让Button的父窗口刷新一下
      

  4.   

    请问chehw 能给我一个简单使用WM_CTLCOLORBTN的例子吗? 
    我在网上找了一圈没找到 
      

  5.   

    TO chehw:
       我响应OnCtlColor()消息,但是它的返回值和你告诉我的不一样啊,是不是我方法不对呢?
       应该怎么做才对啊?
      

  6.   

    MFC下: 先判断nCtlColor是否为CTLCOLOR_BTN, 及pWnd是否为你要设置的button, 再返回(HBRUSH)GetStockObject(NULL_BRUSH);
      

  7.   

    还是不好使啊,我所有的按钮都是想要透明的,所以我在按钮的父窗口中这么写:CSkinButton m_btNoAdd;HBRUSH CGameClientView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
       HBRUSH hbr = CGameFrameView::OnCtlColor(pDC, pWnd, nCtlColor);
       if(nCtlColor == CTLCOLOR_BTN)
       {
         return (HBRUSH)GetStockObject(NULL_BRUSH);
       }   return hbr;
    }但是还是没好,麻烦你再帮我看看行吗,我需不需要在CSkinButton类中,再做些什么呢?
      

  8.   

    HBRUSH CDIALOGDlg::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_EDIT)
            pDC->SetTextColor(RGB(0,0,255));        if(nCtlColor== CTLCOLOR_LISTBOX)
        {
            HBRUSH m_hbrush;
            m_hbrush=CreateSolidBrush(RGB(0,0,0));
            pDC->SetBkMode(TRANSPARENT);
                    //设置字体颜色
            pDC->SetTextColor(RGB(255,255,255));
            return m_hbrush;
        }
        CBrush m_cBrush;
        m_cBrush.CreateSolidBrush(RGB(0,255,255));
        switch(nCtlColor)
        {
        case CTLCOLOR_DLG:
            pDC->SetBkMode(TRANSPARENT);
            break;
        case CTLCOLOR_STATIC:
            pDC->SetTextColor(RGB(255,0,0));
            pDC->SetBkColor(RGB(0,255,255));
            break;
        }
        DeleteObject(m_cBrush);
        // TODO: Return a different brush if the default is not desired
        return hbr;
    }
      

  9.   

    还是没好使啊,DrawTransBitmap 
    只画有图形的地方,不画背景,应该让Button的父窗口刷新一下如何让父窗口刷新呢?
      

  10.   

    还是没好使啊,DrawTransBitmap 
    只画有图形的地方,不画背景,应该让Button的父窗口刷新一下如何让父窗口刷新呢?
      

  11.   

    还是没好使啊,DrawTransBitmap 
    只画有图形的地方,不画背景,应该让Button的父窗口刷新一下如何让父窗口刷新呢?