owner draw CListBox, how to draw "no item found"

Hello,
I have an owner draw listbox, in the DrawItem I draw the items.

If the listbox doesn't contain any item I would like to display a message
"no item found"
but this is no item, so DrawItem is the wrong place.
Where should I do this? OnPaint, OnEraseBkgnd?
I thought I would be able to do something like this for a test (just paint 
the window blue)
but it's always white
BOOL CmyListbox::OnEraseBkgnd(CDC* pDC)
{
    if (m_pItemList.GetCount() < 1)
    {
         CRect rc;
         GetClientRect(&rc);
        pDC->FillSolidRect(rc,RGB(0,0,255));
        return TRUE;
    }
}
how is this supoosed to be done?

regards
Niklas 


0
11/24/2004 10:52:01 AM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
946 Views

Similar Articles

[PageSpeed] 29

Niklas wrote:
> Hello,
> I have an owner draw listbox, in the DrawItem I draw the items.
> 
> If the listbox doesn't contain any item I would like to display a message
> "no item found"
> but this is no item, so DrawItem is the wrong place.
> Where should I do this? OnPaint, OnEraseBkgnd?
> I thought I would be able to do something like this for a test (just paint 
> the window blue)
> but it's always white
> BOOL CmyListbox::OnEraseBkgnd(CDC* pDC)
> {
>     if (m_pItemList.GetCount() < 1)
>     {
>          CRect rc;
>          GetClientRect(&rc);
>         pDC->FillSolidRect(rc,RGB(0,0,255));
>         return TRUE;
>     }
> }
> how is this supoosed to be done?
> 
> regards
> Niklas 
> 
> 


OnEraseBackground is called before any drawing takes place (usually just 
before on item draw). So what will happen with your code there will be 
taht the entire background is drawn blue and then whatever code you have 
in DrawItems will overwrite this. Also i'm not entirly sure 
OnEraseBackground is actually called for owner draw... have you tried 
stepping through it to make sure it's actually called?

What i've done in the past is simply add a dummy item called "No items" 
or "List Empty", then when data arrives I remove that item again.


--
Martin Gill
0
nospam2791 (369)
11/24/2004 12:38:10 PM
Reply:

Similar Artilces:

owner draw CListBox, how to draw "no item found"
Hello, I have an owner draw listbox, in the DrawItem I draw the items. If the listbox doesn't contain any item I would like to display a message "no item found" but this is no item, so DrawItem is the wrong place. Where should I do this? OnPaint, OnEraseBkgnd? I thought I would be able to do something like this for a test (just paint the window blue) but it's always white BOOL CmyListbox::OnEraseBkgnd(CDC* pDC) { if (m_pItemList.GetCount() < 1) { CRect rc; GetClientRect(&rc); pDC->FillSolidRect(rc,RGB(0,0,255)); return TRU...