我从CButton派生了一个CButtonX类,在DrawItem中写字。而主窗口的背景是贴上去的Bitmap,按钮是动态Create的。可是按钮不透明(一个灰色的方框,难看)。哪位大哥指点一下,感激不尽!!!

解决方案 »

  1.   

    自己绘制一个图形按钮
    网上有很多这样的现成的类(CXxxButton)
    建议你到codeguru去下载一个
      

  2.   

    我就是自己绘的啊。我没有画的部分都是灰色!我想没有画的部分是透明的,即是背景的bitmap.
    帮帮忙饿!
      

  3.   

    在你的派生CButtonX类中,映射WM_ERASEBKGND消息,在该消息处理函数中
    BOOL C_your_Dlg::OnEraseBkgnd(CDC* pDC)
    {
    // TODO: 在此添加消息处理程序代码和/或调用默认值 return CDialog::OnEraseBkgnd(pDC); //将这句改为返回1(或0),然后试试
    }
      

  4.   

    重载:
    void CXxxButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {

    // TODO: Add your code to draw the specified item
    CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
    CRect btnRect;
    btnRect.CopyRect(&lpDrawItemStruct->rcItem); 
    pDC->SetBkMode(TRANSPARENT);
    pDC->SetTextColor(RGB(0,0,80));
    pDC->DrawText( "XButton",btnRect,DT_CENTER);
    }
    BOOL CXxxButton::OnEraseBkgnd(CDC* pDC)
    {
        return FALSE;  
    }
      

  5.   

    同意lingfeng8888(棱枫) ,試試先﹗
      

  6.   

    void CXxxButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {

    // TODO: Add your code to draw the specified item
    CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
    CRect btnRect;
    btnRect.CopyRect(&lpDrawItemStruct->rcItem); 
    pDC->SetBkMode(TRANSPARENT);
    pDC->SetTextColor(RGB(0,0,80));
    pDC->DrawText( "XButton",btnRect,DT_CENTER);
    }
    BOOL CXxxButton::OnEraseBkgnd(CDC* pDC)
    {
        return 0;  ////不行的话就改成1
    }
      

  7.   

    HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    // HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    switch (nCtlColor)
    {    
    case CTLCOLOR_STATIC:
    pDC->SetTextColor(RGB(0, 0, 0));
    pDC->SetBkColor(RGB(255,255,255));
    case CTLCOLOR_EDIT:
    pDC->SetTextColor(RGB(0, 0, 0));
    pDC->SetBkColor(RGB(255,255,255));
    case CTLCOLOR_LISTBOX:
    pDC->SetTextColor(RGB(0, 0, 0));
    pDC->SetBkColor(RGB(255,255,255));
    case CTLCOLOR_SCROLLBAR:
    pDC->SetTextColor(RGB(0, 0, 0));
    pDC->SetBkColor(RGB(255,255,255));
    case CTLCOLOR_BTN:
    pDC->SetTextColor(RGB(0, 0, 0));
    pDC->SetBkColor(RGB(255,255,255));
    case CTLCOLOR_DLG:     
    return m_Brush;
    }

    // TODO: Return a different brush if the default is not desired
    return m_Brush;
    }//现在懂了么??
      

  8.   

    你是要求位图的背景不透明,而不是按钮本身透明吧?也就是要像ICON那样是吗?
      

  9.   

    void CXxxButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {

    // TODO: Add your code to draw the specified item
    CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
    CRect btnRect;
    btnRect.CopyRect(&lpDrawItemStruct->rcItem); 
    pDC->SetBkMode(TRANSPARENT);
    pDC->SetTextColor(RGB(0,0,80));
    pDC->DrawText( "XButton",btnRect,DT_CENTER);
    }
    BOOL CXxxButton::OnEraseBkgnd(CDC* pDC)
    {
        return 0;  ////不行的话就改成1
    }
      

  10.   

    up,参考CButtonST
    去http://www.vckbase.com/ 看看
      

  11.   

    CButtonST:
    http://www.vckbase.com/document/viewdoc.asp?id=518http://www.vckbase.com/document/viewdoc.asp?id=519http://www.vckbase.com/document/viewdoc.asp?id=647http://www.vckbase.com/document/viewdoc.asp?id=521http://www.vckbase.com/document/viewdoc.asp?id=520http://www.vckbase.com/document/viewdoc.asp?id=517