Thread: image lists, icons and treeviews

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    image lists, icons and treeviews

    i want to learn the basics of images in win32. id just like to add a standard Windows icon to an image list and then use that image list with my treeview control. can someone help? no mfc please.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    i tried it on my own while waiting for some gracious soul to reply to this post(which hasn't happened), and i had troubles setting the image list to the tree view control. code:

    Code:
    HBITMAP hBit;
    HIMAGELIST hList;
    			
    hBit=(HBITMAP)LoadImage(NULL,"icon.ico",IMAGE_ICON,0,0,LR_LOADFROMFILE);
    hList=ImageList_Create(16,16,ILC_COLOR,1,0);
    ImageList_Add(hList,hBit,NULL);
    
    TreeView_SetImageList(hwndTree,hList,TVSIL_NORMAL);
    the last line of code returns NULL. what have i done wrong?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    i found out some more stuff. i can load in a bitmap, but not an icon. ie, not a .ico file. heres the icon code that doesn't work.

    Code:
    HBITMAP hBit;
    HIMAGELIST hList;
    
    hBit=(HBITMAP)LoadImage(NULL,"gta3.ico",IMAGE_ICON,32,32,LR_LOADFROMFILE);
    hList=ImageList_Create(32,32,ILC_COLOR,1,1);
    ImageList_Add(hList,hBit,(HBITMAP)NULL);
    after that code, i check the image count in the list, and there's nothing there, but it works fine with a normal bitmap. does that help anyone to help me?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    Registered User dizolve's Avatar
    Join Date
    Dec 2002
    Posts
    68
    I'm not experienced with image lists but try LoadIcon

      __               &n bsp;      ___ & nbsp;       &nb sp;       &nbsp ;    
     /\ \  __    &nbs p;           /\_ \      &nbsp ;        & nbsp;     
     \_\ \/\_\  ____     _ __\//\ \    __  __&n bsp;    __   
     /'_` \/\ \/\_ ,`\  / __`\\ \ \  /\ \/\ \  /'__`\ 
    /\ \_\ \ \ \/_/  /_/\ \_\ \\_\ \_\ \ \_/ |/\  __/ 
    \ \___,_\ \_\/\____\ \____//\____\\ \___/ \ \____\
     \/__,_ /\/_/\/____/\/___/ \/____/ \/__/   \/____/
            &n bsp; I have a BAD figlet& nbsp;addiction.

  5. #5
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    loadicon is for loading resources. i want to load directly from an .ico file. someone must know how to do it.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  6. #6
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    oops i posted twice. the second one is updated.
    Last edited by bennyandthejets; 01-09-2003 at 10:20 PM.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  7. #7
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    ok, i gave in and made the icon a resource. now i cant work out how to load the resource. i loaded it successfully with loadicon when i made it the hIcon of the window class, but i couldn't get loadicon OR loadimage to work when i tried to add it to an image list.

    Code:
    HBITMAP hBit;
    HIMAGELIST hList;
    		
    hBit=(HBITMAP)LoadImage(hInst,(LPCTSTR)IDI_APP,IMAGE_ICON,16,16,NULL);
    hList=ImageList_Create(16,16,ILC_COLOR,1,1);
    ImageList_Add(hList,hBit,(HBITMAP)NULL);
    No image is added to the list.
    ???
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  8. #8
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291
    What about ImageList_AddIcon()?

    ImageList_AddIcon(HIMAGELIST himl, HICON hicon);
    Staying away from General.

  9. #9
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    yeah that turned out to be the one. i looked through my win32 reference, and surprise surprise, addicon appears. i feel like real jerk .
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed