Treeview - Win32 API

This is a discussion on Treeview - Win32 API within the Windows Programming forums, part of the Platform Specific Boards category; I have a treeview control with an imagelist added but the images only appear next to the items when they're ...

  1. #1
    dizolve
    Guest

    Treeview - Win32 API

    I have a treeview control with an imagelist added but the images only appear next to the items when they're selected and then disappear when deselected. I need the icons to be there all of the time.


    Code:
    	TVITEM tvi;
    	TVINSERTSTRUCTURE tvs;
    	HTREEITEM hti;
    	HBITMAP hbmp;
    	HIMAGELIST himg;
    	int checknone, checksub, checked;
    
    	hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "", WS_CHILD|TVS_HASLINES|TVS_SHOWSELALWAYS, CW_USEDEFAULT, CW_USEDEFAULT,
    			500, 300, phWnd, NULL, gInstance, NULL);
    
    	himg = ImageList_Create(10, 10, FALSE, 3, 0);
    
    	hbmp = LoadBitmap(gInstance, MAKEINTRESOURCE(NV_BITMAP_LB));
    	checknone = ImageList_Add(himg, hbmp, NULL);
    	DeleteObject(hbmp);
    	
    	hbmp = LoadBitmap(gInstance, MAKEINTRESOURCE(NV_BITMAP_LB2));
    	checksub = ImageList_Add(himg, hbmp, NULL);
    	DeleteObject(hbmp);
    	
    	hbmp = LoadBitmap(gInstance, MAKEINTRESOURCE(NV_BITMAP_LB3));
    	checked = ImageList_Add(himg, hbmp, NULL);
    	DeleteObject(hbmp);
    
    	TreeView_SetImageList(hwnd, himg, TVSIL_NORMAL);
    
    	tvi.mask = TVIF_TEXT|TVIF_IMAGE;
    	tvi.pszText = "Test";
    	tvi.cchTextMax = 5;
    	tvs.item = tvi;
    	tvs.hParent = TVI_ROOT;
    	tvi.iImage = checknone;
    	tvi.iSelectedImage = checknone;
    	hti = (HTREEITEM)SendMessage(hwnd, TVM_INSERTITEM, 0, (LPARAM)&tvs);
    	tvs.hParent = hti;
    	SendMessage(hwnd, TVM_INSERTITEM, 0, (LPARAM)&tvs);
    	SendMessage(hwnd, TVM_INSERTITEM, 0, (LPARAM)&tvs);

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    I use similar code without problems.

    Try

    In the CreateWindow you have used the child style but not set an ID for the control. (HMENU param is cast to an int ID if the WS_CHILD style is used)

    Try some error checking

    // Fail if not all of the images were added.
    if (ImageList_GetImageCount(himg)<NUM_BMPS)
    return FALSE;

    I also use

    tvi.hInsertAfter=TVI_LAST;
    "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. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 04:26 PM
  2. OpenSSL and Win32 SSL API :: SSL/TLS
    By kuphryn in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-10-2004, 07:46 PM
  3. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 07:51 PM
  4. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 06:57 PM
  5. Thread Synchronization :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2002, 10:09 AM

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