Override OnPaint in ATL/WTL 
Author Message
 Override OnPaint in ATL/WTL

I am trying to overide the OnPaint method on the CListViewCtrl so that
if no items are visible, a message to that effect would be displayed on
the control. Below is the definition and declaration of a derived class
of CListViewCtrl. It appears to work great if no item are present, but
fails to past the message to the base class (thus no re-painting when
items are present). Any suggestions or pointers on how to resolve this?

TIA

    R

----------------------------------------------
// ListCtrl..h
class ListCtrl : public CWindowImpl<ListCtrl, CListViewCtrl>
{
public:
 ListCtrl();
 virtual ~ListCtrl();

public:
   BEGIN_MSG_MAP(ListCtrl)
      MESSAGE_HANDLER(WM_PAINT, OnPaint)
   END_MSG_MAP()

public:
 LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/,
BOOL& /*bHandled*/);

Quote:
};

// ListCtrl.cpp
LRESULT ListCtrl::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
   if (GetItemCount() <= 0) {

      COLORREF text_color = ::GetSysColor(COLOR_WINDOWTEXT);
      COLORREF bkgrd_color = ::GetSysColor(COLOR_WINDOW);

      PAINTSTRUCT ps;
      HDC hdc = BeginPaint(&ps);

      CRect rect;
      GetClientRect(&rect);

      SetTextColor(text_color);
      SetBkColor(bkgrd_color);

      CString text((LPCTSTR)IDS_NO_ITEMS);

      CSize size;
      GetTextExtentPoint32(hdc, text, text.GetLength(), &size);

      rect.top += size.cy;
      rect.bottom = rect.top + size.cy;

      DrawText(hdc, text, -1, &rect, DT_CENTER | DT_WORDBREAK |
DT_NOPREFIX | DT_NOCLIP);

      EndPaint(&ps);
   }

   return S_OK;

Quote:
}

--------------------------------------------


Tue, 23 Mar 2004 00:54:06 GMT  
 Override OnPaint in ATL/WTL
bHandled is initialized to TRUE before the handler is called. Set it to
FALSE when you want further processing
--
With best wishes,
    Igor Tandetnik


Quote:
> I am trying to overide the OnPaint method on the CListViewCtrl so that
> if no items are visible, a message to that effect would be displayed on
> the control. Below is the definition and declaration of a derived class
> of CListViewCtrl. It appears to work great if no item are present, but
> fails to past the message to the base class (thus no re-painting when
> items are present). Any suggestions or pointers on how to resolve this?

> TIA

>     R

> ----------------------------------------------
> // ListCtrl..h
> class ListCtrl : public CWindowImpl<ListCtrl, CListViewCtrl>
> {
> public:
>  ListCtrl();
>  virtual ~ListCtrl();

> public:
>    BEGIN_MSG_MAP(ListCtrl)
>       MESSAGE_HANDLER(WM_PAINT, OnPaint)
>    END_MSG_MAP()

> public:
>  LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/,
> BOOL& /*bHandled*/);

> };

> // ListCtrl.cpp
> LRESULT ListCtrl::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
> bHandled)
> {
>    if (GetItemCount() <= 0) {

>       COLORREF text_color = ::GetSysColor(COLOR_WINDOWTEXT);
>       COLORREF bkgrd_color = ::GetSysColor(COLOR_WINDOW);

>       PAINTSTRUCT ps;
>       HDC hdc = BeginPaint(&ps);

>       CRect rect;
>       GetClientRect(&rect);

>       SetTextColor(text_color);
>       SetBkColor(bkgrd_color);

>       CString text((LPCTSTR)IDS_NO_ITEMS);

>       CSize size;
>       GetTextExtentPoint32(hdc, text, text.GetLength(), &size);

>       rect.top += size.cy;
>       rect.bottom = rect.top + size.cy;

>       DrawText(hdc, text, -1, &rect, DT_CENTER | DT_WORDBREAK |
> DT_NOPREFIX | DT_NOCLIP);

>       EndPaint(&ps);
>    }

>    return S_OK;
> }
> --------------------------------------------



Tue, 23 Mar 2004 01:04:32 GMT  
 Override OnPaint in ATL/WTL
Thanks, that is the clue I was missing :)

    R

Quote:

> bHandled is initialized to TRUE before the handler is called. Set it to
> FALSE when you want further processing
> --
> With best wishes,
>     Igor Tandetnik



> > I am trying to overide the OnPaint method on the CListViewCtrl so that
> > if no items are visible, a message to that effect would be displayed on
> > the control. Below is the definition and declaration of a derived class
> > of CListViewCtrl. It appears to work great if no item are present, but
> > fails to past the message to the base class (thus no re-painting when
> > items are present). Any suggestions or pointers on how to resolve this?

> > TIA

> >     R

> > ----------------------------------------------
> > // ListCtrl..h
> > class ListCtrl : public CWindowImpl<ListCtrl, CListViewCtrl>
> > {
> > public:
> >  ListCtrl();
> >  virtual ~ListCtrl();

> > public:
> >    BEGIN_MSG_MAP(ListCtrl)
> >       MESSAGE_HANDLER(WM_PAINT, OnPaint)
> >    END_MSG_MAP()

> > public:
> >  LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/,
> > BOOL& /*bHandled*/);

> > };

> > // ListCtrl.cpp
> > LRESULT ListCtrl::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
> > bHandled)
> > {
> >    if (GetItemCount() <= 0) {

> >       COLORREF text_color = ::GetSysColor(COLOR_WINDOWTEXT);
> >       COLORREF bkgrd_color = ::GetSysColor(COLOR_WINDOW);

> >       PAINTSTRUCT ps;
> >       HDC hdc = BeginPaint(&ps);

> >       CRect rect;
> >       GetClientRect(&rect);

> >       SetTextColor(text_color);
> >       SetBkColor(bkgrd_color);

> >       CString text((LPCTSTR)IDS_NO_ITEMS);

> >       CSize size;
> >       GetTextExtentPoint32(hdc, text, text.GetLength(), &size);

> >       rect.top += size.cy;
> >       rect.bottom = rect.top + size.cy;

> >       DrawText(hdc, text, -1, &rect, DT_CENTER | DT_WORDBREAK |
> > DT_NOPREFIX | DT_NOCLIP);

> >       EndPaint(&ps);
> >    }

> >    return S_OK;
> > }
> > --------------------------------------------



Tue, 23 Mar 2004 01:25:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. About override the OnPaint function.

2. About override the OnPaint function!

3. OnPaint override on CListViewCtrl?

4. CListView - Overriding OnPaint()

5. Overriding OnPaint of CListView

6. OnPaint() override

7. Can we override a control's OnPaint ?

8. CListBox -- Owner Drawn - (override OnPaint) - Need help, please!

9. Overriding the OnPaint method for button controls

10. overriding events (OnPaint, OnClick, etc.)

11. WTL - Very new to WTL - Trying to insert new COM object in WTL

12. Unexpected CMainFrame::OnPaint() message from ATL window that employs IWebBrowser

 

 
Powered by phpBB® Forum Software