Click to See Complete Forum and Search --> : Struct for WM_DRAWITEM Message
SteveMurphy
December 13th, 2004, 01:47 PM
I have to send a WM_DRAWITEM message to a listbox. The documentation says that the lParam is the DRAWITEMSTRUCT for the item to be drawn.
Is there a function I can call to populate the members of the struct before issuing the call?
Thanks.
HeartBreakKid
December 13th, 2004, 02:16 PM
Generally, you will not send WM_DRAWITEM messages. I can't think of any good reason to. If you need to repaint a control, you can call Invalidate(), InvalidateRect(), or in the case of a List control call RedrawItems().
NoHero
December 13th, 2004, 02:17 PM
I don't think so, I think you must initialize this structure on your own:
DRAWITEMSTRUCT it;
ZeroMemory(&it, sizeof(DRAWITEMSTRUCT));
it.CtlType = ODT_LISTBOX;
it.CtlID = IDC_LISTBOX; // Insert the resource identifier of your list box here
it.itemID = 0; // Item to be drawn
it.itemAction = ODA_SELECT; // See MSDN for more flags here. This will draw the item selected
it.itemState = ODS_SELECTED; // More flags > look at MSDN
it.hwndItem = GetDlgItem(IDC_LISTBOX);
it.hDC = GetDC(it.hwndItem);
GetWindowRect(it.rcItem); // Rectangle of your listbox
it.itemData = 0; // If you want to associate some data with the item
Haven't figured it out, but it should work :wave:
NoHero
December 13th, 2004, 02:19 PM
Generally, you will not send WM_DRAWITEM messages. I can't think of any good reason to. If you need to repaint a control, you can call Invalidate(), InvalidateRect(), or in the case of a List control call RedrawItems().
Of course, redrawing only one item is much more efficent if you have a ton of items. So this can be quiet helpful. RedrawItem is the most efficient of course, it allows you the same. So I think this is the proper solution.
SteveMurphy
December 13th, 2004, 05:01 PM
Thanks everybody.
To keep it simple, I decided to first try the InvalidateRect suggested by HeartBreakKid. Also, I'm not using MFC, so I can't use RedrawItems.
My app compiles/links fine, but it crashes. Please look at the following code and tell me if you see errors:
LPRECT pRect = 0;
SendMessage(m_hListBox,LB_GETITEMRECT, (WPARAM) idx, (LPARAM) pRect);
InvalidateRect(m_hListBox,pRect,TRUE);
UpdateWindow(m_hListBox);
TIA
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.