List Views are blowing my mind right now. Nothing shows up. The items are being added: A scroll bar appears, but no items show up.
Here's the code:
Code:
HWND hwndWadList;
void WadList_Update()
{
LV_ITEM lvi;
DoomLump *lump;
unsigned int nlumps, x;
char text[10];
ListView_DeleteAllItems(hwndWadList);
ZeroMemory(&lvi, sizeof(LV_ITEM));
lvi.mask = LVIF_TEXT;
nlumps = wad_pwad->LumpCount();
//ListView_SetItemCount(hwndWadList, nlumps);
for(x = 0; x < (nlumps > 10 ? 10 : nlumps); x++)
{
lump = wad_pwad->GetLump(x);
strcpy(text, lump->GetName());
lvi.pszText = (char *) lump->GetName();
MessageBox(GetParent(hwndWadList), lump->GetName(), "", MB_OK);
lvi.iItem = x;
ListView_InsertItem(hwndWadList, &lvi);
}
}
The MessageBox() does display the name of the item, and it does show text. lump->GetName() is returning what it should. It's currently set to only do the first ten, because I didn't want bazillions of MessageBoxes. I know I shouldn't do the (char *) cast (it's casting it from const char *, doesn't really matter much) but it's only for debugging. I tried copying the data to a temporary buffer, text, and got the same result. (The rements are still visible...)
Anyways, why is the pszText member not const? And why do I get a scrollbar and no items?
Thanks!
UPDATE: {1/1/06}
Ok, I decided to check some error codes, always a good place to start. ListView_InsertItem is returning success (the index of the inserted item) So I added another loop outside and after my first for() loop to enumerate the names of all the items in the listbox. (Just to check.) It does so, and does it correctly! (I'm using ListView_GetItemText()...) But still the ListView remains a white box. (The scrollbar still appears if I shrink the window, so the ListView thinks there are items there... they're just not appearing.) Here is the revised convoluted debug ridden code I'm using: (Results haven't changed...)
Code:
void WadList_Update()
{
LV_ITEM lvi;
DoomLump *lump;
unsigned int nlumps, x;
char text[10], err_buf[20], txtret[20];
int lvi_result;
ListView_DeleteAllItems(hwndWadList);
ZeroMemory(&lvi, sizeof(LV_ITEM));
lvi.mask = LVIF_TEXT;
nlumps = wad_pwad->LumpCount();
//ListView_SetItemCount(hwndWadList, nlumps);
for(x = 0; x < (nlumps > 10 ? 10 : nlumps); x++)
{
lump = wad_pwad->GetLump(x);
strcpy(text, lump->GetName());
lvi.pszText = text;
MessageBox(GetParent(hwndWadList), lump->GetName(), "", MB_OK);
lvi.iItem = x;
lvi_result = ListView_InsertItem(hwndWadList, &lvi);
sprintf(err_buf, "%d", lvi_result);
MessageBox(GetParent(hwndWadList), err_buf, "", MB_OK);
}
for(x = 0; x < (nlumps > 10 ? 10 : nlumps); x++)
{
ListView_GetItemText(hwndWadList, x, 0, txtret, 20);
MessageBox(GetParent(hwndWadList), txtret, "", MB_OK);
}
}
Sorry for the lengthy edit - thanks in advance for any insight. I'm at the end of my wit for now...
Edit: If it helps, here's the ListView's creation:
Code:
hwndWadList = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEWA, "", WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_NOCOLUMNHEADER, 0, 0, 100, 100, hwnd, NULL, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
Edit: Resolved!
Inspiration hit me. Despite giving it the LVS_NOCOLUMNHEADER style, it still has columns. (Duh, just no headers.) But I'd never specified the columns. Adding the needed code, things appears. I was looking at the wrong piece of code. (It'd kill them to document this? Or at least have the control have some default... like a blank column at 100px?) Thanks CBoard for at least letting me boil off some stress, problem solved!