views:

787

answers:

2

How to develop a ListView that has No background so that my Background image is displayed properly... I' not able to get through with this...

+1  A: 

Have a look at this article and there is a control library which supports alpha blending which you might be able to extend to the ListView control as well.

tomlog
+1  A: 

You do it the same way you would in win32.

All you need to do is subclass the control and override the WM_ERASEBKGND window message. You can also override the WM_CTLCOLOR message to set the text mode into TRANSPARENT.

I've done this on almost all the standard controls and it works fine.

Update:

This a starting example in MFC, you still need to draw the background onto the control by some method.

    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;
}
Shane Powell
Can you please give more light on this method of your it would be highly helpful...
y ramesh rao
Updated answer with example.
Shane Powell