column won't appear
well since I finally got a working dialog box with the API, today I figured I'd try adding a listview control to it.
first of all let me tell you how I created the listview control. I created it in my dialog with the Visual C++ visual resource editor (APSTUDIO I believe its called, I am sure you know what I mean). I am using the Win32 API, but instead of hardcoding my resource files, I prefer to use the built in tool in Visual C++.
I tried adding a column based on code I seen posted here:
here is my dialog callback:
I know its very simple code, I am just trying to see if I can get something looking the way I want it. hwndList is an HWND global, and lvCol is an LVCOLUMN global. it compiles fine, but when I run it, the column does not get added.
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
hwndList = GetDlgItem(hwndDlg, IDC_LIST);
ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
lvCol.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT;
lvCol.fmt = LVCFMT_LEFT;
lvCol.iSubItem = 0;
lvCol.cx = 200;
lvCol.pszText = "File";
ListView_InsertColumn(hwndList, 0, &lvCol);
return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
would anyone here be able to tell me why this isn't working? I realize the listview control in the above link I posted was created with CreateWindow(), but I don't see why that would matter here (or maybe it does?). using CreateWindow() would make this harder, since I would need to set the dimensions to properly display it in the dialog.
any help is greatly appreciated as always.
thank you in advance! :)
Your code looks fine, except that a dialog procedure should not call DefWindowProc (as yours is doing in WM_COMMAND). It should always return TRUE or FALSE.
A couple of other things that come to mind. Does your list-view have the LVS_REPORT style (this is my best guess)? Is the list-view showing up at all? If not, make sure you have called InitCommonControls before displaying the dialog.
You have the wrong view style for the list view control. Columns only show up with report style - otherwise your request to insert a new column will do 100% nothing.
thanks for telling me that, I didn't really check the values DefWindowProc() returns on msdn, I just got the idea from a book (it was using it in a window callback function). now that I have it working I can actually start adding the commands instead of using DefWindowProc(). :)
that was it. I checked the listview control's properties and I had it on "List". I changed it to "Report", and it works fine now. :)
thanks anonytmouse and Bubba :D .
I only know because I, too, attempted to add columns with the wrong style of view for about 2 hours and could not figure out why it wouldn't work.
After much Advil and knashing of teeth I interpreted the cryptic SDK docs and figured it out. MS help writers please do not start writing books or teaching. We'd all be lost.