Thread: ListView_InsertItem is failing!

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

    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
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    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 08: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
    310
    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,868
    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, 03:32 AM
  2. pointer comparison failing
    By Bleech in forum C Programming
    Replies: 4
    Last Post: 08-11-2007, 06: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, 12:08 PM
  5. initializes all components of failing to false
    By romeoz in forum C++ Programming
    Replies: 21
    Last Post: 08-01-2003, 09:30 PM