I'm trying to create this List View control, but somehow I can't load any column to it, here's the code and below is the .rc line for listview, any suggestions? also those string columns are gonna be changed dynamically depending on the file (it will load them from file), this is just for testing
What is the value you get for the handle to the List View control? I get NULL if I try to get it with GetDlgItem in WM_CREATE. But if I use PostMessage to send myself a custom message in WM_CREATE and then run the same code there, it's fine.
It think the problem is that the dialog template processing hasn't been done when WM_CREATE is called, so the dialog's child controls don't yet exist; they get created between WM_CREATE and WM_INITDIALOG.
But because you're using a a custom WndProc for your dialog, it doesn't appear to get sent WM_INITDIALOG like a normal dialog; so you have to send yourself a custom message instead.
oh yeah, I have this basic "template" for all my win32 apps and there IS PostMessage that posts MY_WM_INITDIALOG, that YOU did approx 1 year ago when I was starting with GUI apps, (when you described how to end dialogbox/createdialog and stuff), but few weeks ago I totally forgot about this (that I need my own init message for main window as dialog) and I just deleted it, since it was kinda weird, having PostMessage that does everything I want to do on create, thanks! it works now :)
edit: actually, I still need some hlep with listview,
I have this code right here
lvc.cx = 60;
and my listview has width 180, therefore it should be enough for 3 columns, also my columns are supposed to have text centered
lvc.fmt = LVCFMT_CENTER;
HOWEVER with 3 columns I still have a LOT of space left, AND the first column is not centered, any suggestion?
For some reason, the alignment value is ignored for the first column. The remarks from the MSDN entry for LVCOLUMN suggest you add a dummy first column, add the columns you want (with the required alignments), and then delete the dummy first column.
If you still have too much space, maybe you need to make the list narrower and use the extra dialog space for something else? Poss. even an image??
If a column is added to a list-view control with index 0 (the leftmost column), it is always LVCFMT_LEFT. Setting other flags on column 0 does not override that alignment. Therefore if you keep inserting columns with index 0, the text in all columns are left-aligned. If you want the first column to be right-aligned or centered you can make a dummy column, then insert one or more columns with index 1 or higher and specify the alignment you require. Finally delete the dummy column.
1. is there a NEED to do a dummy column? since it's working just fine when I start with 1, except 0, ANYWAY, I just tried to actually do 1 for everything (iSubItem = 1, insert column second parameter is 1 too) and the listview looks just like every other (with changing isubitem), what is the difference? why do I need to set different iSubItem values ?
1 2 3 4 5 6 7
for(int i = 0; i < COLUMN_MAX; i++)
lvc.iSubItem = 1;
lvc.pszText = (char*)sColumn[i].c_str();
ListView_InsertColumn(hTemp, 1, &lvc);
2. also it's not that there's too much space, it's that it's width is 180, while width of one column is supposed to be 60, I have 3 columns, therefore 3x60 = 180, so it should fill whole listview, but it's not, why is that?
3. also will listview take care of sorting automatically when I click on one of those columns (just like in explorer) or do I have to program it too?