2009-06-10 71 views

回答

1

看一看this文章,並且有支持alpha混合的control library,您可能也可以將其擴展到ListView控件。

1

你這樣做你會在win32中。

您所需要做的就是對控件進行子類化並覆蓋WM_ERASEBKGND窗口消息。您還可以覆蓋消息WM_CTLCOLOR以將文本模式設置爲TRANSPARENT。

我已經在幾乎所有的標準控件上做了這個,它工作正常。

更新:

這在MFC中啓動例如,你仍然需要繪製背景上用某種方法控制。

class TransparentListView : public CListView 
    { 
    public: 
     TransparentListView(); 
     virtual ~ToolsListCtrl(); 

    protected: 
     afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/); 
     afx_msg BOOL OnEraseBkgnd(CDC* pDC); 

    private: 
     DECLARE_MESSAGE_MAP(); 
    }; 

IMPLEMENT_DYNAMIC(TransparentListView , CListView) 
TransparentListView::TransparentListView() 
{ 
} 

TransparentListView::~TransparentListView() 
{ 
} 

BEGIN_MESSAGE_MAP(TransparentListView, CListView) 
    ON_WM_CTLCOLOR_REFLECT() 
    ON_WM_ERASEBKGND() 
END_MESSAGE_MAP() 

HBRUSH TransparentListView::CtlColor(CDC* pDC, UINT /*nCtlColor*/) 
{ 
    pDC->SetBkMode(TRANSPARENT); 
    return (HBRUSH)GetStockObject(NULL_BRUSH); 
} 

BOOL TransparentListView::OnEraseBkgnd(CDC* pDC) 
{ 
    // You will need to force the drawing of the background here 
    // onto the pDC, there are lots of ways to do this. 
    // I've done it my having a pointer to a interface that 
    // draws the background image 
    return TRUE; 
} 
+0

可以請你給這個方法更多的燈光你會很有幫助... – 2009-06-10 12:37:29