2009-06-10 75 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