Click to See Complete Forum and Search --> : Listbox LB_SETITEMDATA not working?


indiocolifa
September 14th, 2003, 03:55 AM
I've the following problem developing my new version of Message Cracker Wizard utility (URL is below) while trying to display ownerdrawn bitmaps on a listbox.

I set associated bitmaps with this:


for (int i = 0; i < numMessages; i++)
{
SendDlgItemMessage (hwnd, IDC_MESSAGES, LB_ADDSTRING, 0, (LPARAM)msginfo[i].WM_msg);
// add a bitmap index depending on type
SendDlgItemMessage (hwnd, IDC_MESSAGES, LB_SETITEMDATA, (WPARAM)i, (LPARAM)msginfo[i].fType);
}


where fType is an int telling the message type (and the bitmap type, of course).

The problem is that I get always no bitmap change.

void Cls_OnDrawItem(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem)
{
char szTextBuf[MAX_PATH];
HDC hdcMem;
HGDIOBJ hbmpOld;
HBITMAP hPic;
int x = lpDrawItem->rcItem.left;
int y = lpDrawItem->rcItem.top;
UINT iBitmap;

switch (lpDrawItem->itemAction)
{
case ODA_DRAWENTIRE:

// Draw message bitmap depending on type

switch (lpDrawItem->itemData)
{
case KEYBOARD:
hPic = hbmpKeyboard;
break;

case MOUSE:
hPic = hbmpMouse;
break;

default:
hPic = hbmpMouse;
break;
}


lpDrawItem->ItemData always = 0!!!

why?
thanks!

NigelQ
September 14th, 2003, 11:10 AM
Try using the index returned by the LB_ADDSTRING instead of your own index...

for (int i = 0; i < numMessages; i++)
{
int iIndex;

iIndex = SendDlgItemMessage (hwnd, IDC_MESSAGES, LB_ADDSTRING, 0, (LPARAM)msginfo[i].WM_msg);
// add a bitmap index depending on type
SendDlgItemMessage (hwnd, IDC_MESSAGES, LB_SETITEMDATA, (WPARAM)iIndex, (LPARAM)msginfo[i].fType);
}


Also, do you have the LBS_HASSTRINGS style set?

Hope this helps,

- Nigel

indiocolifa
September 14th, 2003, 01:35 PM
YEEES!!!

thank you!

NigelQ
September 14th, 2003, 01:41 PM
You're welcome :D

- Nigel