ListView_InsertItem is failing!

This is a discussion on ListView_InsertItem is failing! within the Windows Programming forums, part of the Platform Specific Boards category; Code: int DumpCompiler(HWND hwnd, char *pStr) { LVITEM item = {0}; item.mask = LVIF_TEXT; item.pszText = pStr; item.iItem = ListView_GetItemCount(hwnd); ...

  1. #1
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308

    Unhappy ListView_InsertItem is failing!

    Code:
    int DumpCompiler(HWND hwnd, char *pStr) {
    	LVITEM item = {0};
    	item.mask = LVIF_TEXT;
    	item.pszText = pStr;
    	item.iItem = ListView_GetItemCount(hwnd);
    	ListView_InsertItem(hwnd, &item);
        return ListView_EnsureVisible(hwnd, item.iItem, 0);
    }
    This is how I create the ListView
    Code:
    INITCOMMONCONTROLSEX iccx;
    			iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
    			iccx.dwICC = ICC_BAR_CLASSES|ICC_LISTVIEW_CLASSES;
    			InitCommonControlsEx(&iccx);
    
    hCompiler = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL, WS_CHILD|WS_VISIBLE|LVS_REPORT|LVS_SINGLESEL|LVS_NOCOLUMNHEADER|LVS_SORTDESCENDING, 5, 280, 0, 0, hWnd, HMENU(IDC_COMPILER), hInstance, 0);
    			ListView_SetBkColor(hCompiler, RGB(0,0,0));
    			ListView_SetTextColor(hCompiler, RGB(0,255,0));
    			ListView_SetTextBkColor(hCompiler, RGB(0,0,0));
    When I use:
    Code:
    DumpCompiler(hCompiler, "Hola");
    Nothing happens...any ideas?
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  2. #2
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Usually when a window won't respond and I think it should, it's because the window hasn't actually finished being created yet. CreateWindowEx() only guarantees that the window will be created at some point in the future -- it will return before the window has finished initializing.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Did you notice your listview has height and width 0?

    Edit: There's another problem too. You're using the LVS_REPORT style which requires the listview to have columns. Try inserting a column (or removing that style):
    Code:
    LVCOLUMN lvc = {0};
    lvc.mask = LVCF_WIDTH;
    lvc.cx = 200; //or whatever column width you want
    ListView_InsertColumn(hCompiler,0,&lvc);
    Last edited by JaWiB; 08-21-2006 at 09:49 PM.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I think JaWiB has the solution.

    You may also be interested in this list-view sample.

  5. #5
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308
    Ok, I'll check the link, but I'd like to add lines like the listbox, but the idea of using listview is that I can change in runtime the fore and back color.
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Quote Originally Posted by Joelito
    but I'd like to add lines like the listbox.
    Add the extended style

    LVS_EX_GRIDLINES
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 09-23-2008, 04:32 AM
  2. pointer comparison failing
    By Bleech in forum C Programming
    Replies: 4
    Last Post: 08-11-2007, 07:33 PM
  3. CreateDevice failing
    By MadCow257 in forum Game Programming
    Replies: 6
    Last Post: 03-14-2006, 09:03 PM
  4. GetDIBits() failing
    By Epo in forum Windows Programming
    Replies: 3
    Last Post: 09-19-2005, 01:08 PM
  5. initializes all components of failing to false
    By romeoz in forum C++ Programming
    Replies: 21
    Last Post: 08-01-2003, 10:30 PM

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