column won't appear

This is a discussion on column won't appear within the Windows Programming forums, part of the Platform Specific Boards category; hello all, well since I finally got a working dialog box with the API, today I figured I'd try adding ...

  1. #1
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211

    column won't appear

    hello all,
    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:
    http://cboard.cprogramming.com/showt...752#post422752

    here is my dialog callback:

    Code:
    BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch(uMsg) {
    	case WM_INITDIALOG:
    		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 TRUE;
    	case WM_COMMAND:
    		switch(LOWORD(wParam)) {
    		default:
    			return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
    		}
    		break;
    	case WM_CLOSE:
    		EndDialog(hwndDlg, 0);
    
    		return TRUE;
    	}
    
    	return FALSE;
    }
    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.

    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!
    Last edited by Bleech; 08-23-2006 at 10:29 PM.

    Intel Core 2 Quad Q6600 @ 2.40 GHz
    3072 MB PC2-5300 DDR2
    2 x 320 GB SATA (640 GB)
    NVIDIA GeForce 8400GS 256 MB PCI-E

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    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.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,515
    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.
    Arrogance breeds bad code

  4. #4
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211
    @anonytmouse:

    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().

    @Bubba:

    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 .

    Intel Core 2 Quad Q6600 @ 2.40 GHz
    3072 MB PC2-5300 DDR2
    2 x 320 GB SATA (640 GB)
    NVIDIA GeForce 8400GS 256 MB PCI-E

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,515
    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.
    Arrogance breeds bad code

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IF CONDITION plese help
    By birumut in forum C Programming
    Replies: 12
    Last Post: 03-06-2009, 08:48 PM
  2. BorlandC proj
    By mary18 in forum C Programming
    Replies: 68
    Last Post: 02-20-2008, 10:22 AM
  3. Retrieving Multiple inputs with fgets?
    By Axel in forum C Programming
    Replies: 25
    Last Post: 09-13-2005, 04:04 PM
  4. Bitwise OR
    By tinkerbell20 in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2005, 02:23 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21