Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Only one Icon in my treeview!

Only one Icon in my treeview!

Scheduled Pinned Locked Moved C / C++ / MFC
phpdata-structuresquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CrocodileBuck
    wrote on last edited by
    #1

    Hi ;), i coded a working treeview(SDI/Windows Explorer Style), but hardly without icons, there is shown only one icon in my treeview. Pic ;) : http://filehosting.at/images/download.php?file=b14ad20aa1a01412004995061e3202bb I want to show the original explorer icons in my treeview so i tried it with

    SHGetFileInfo()

    ...but it won't work :confused: Here is some sample code (i don't want to post too much): 1. This function detects the drives and labels :

    **void CLeftView::CreateRoots()
    {
    CString strMessage;
    int nPos = 65;
    CString strDrive;
    TCHAR szLabel[128];
    DWORD dwVolumeSerialNumber;
    DWORD dwMaxNameLength;
    DWORD dwFileSystemFlags;
    TCHAR szFileSysName[128];

    UINT	uDriveType;
    CString cstrWirDir;
    TCHAR	infoBuf\[INFO\_BUFFER\_SIZE\];
    DWORD	dwDriveList = GetLogicalDrives ();			// Anzahl der Laufwerke ermitteln
    

    //----------------------------------------------------------------------------------------------------------------

    GetWindowsDirectory(infoBuf, INFO\_BUFFER\_SIZE);
    cstrWirDir = infoBuf;
    cstrWirDir = cstrWirDir.GetAt(0);
    cstrWirDir = cstrWirDir + ":";
    

    //----------------------------------------------------------------------------------------------------------------

    while (dwDriveList) 
    {
        if (dwDriveList & 1) 
    	{
    		strDrive = "?:\\\\";
            strDrive.SetAt (0,nPos);
    		uDriveType = GetDriveType(strDrive);
    		
    		GetVolumeInformation (strDrive, szLabel,
    					          sizeof( szLabel ) - 1,
    							  &dwVolumeSerialNumber,
    							  &dwMaxNameLength,
    							  &dwFileSystemFlags,
    							  szFileSysName,
    							  sizeof( szFileSysName ) - 1);	
    		
    		switch(uDriveType)
    		{
    
    			// ToDo: Wenn kein Name für Diskettenlaufwerk(und andere), dann vorgefertigtes Label
    			case 2: // Diskettenlaufwerk
    				strDrive = strDrive.Left(2);
    				InsertFileItem("3½-Diskette (" + strDrive +")");
    				break;
    			case 3: // Festplatte
    				strDrive = strDrive.Left(2);
    				// AfxMessageBox(strDrive, MB\_OK);
    				InsertFileItem((CString)szLabel + " (" + strDrive +")");
    				break;
    			case 5: // CD-Rom
    				strDrive = strDrive.Left(2);
    				InsertFileItem((CString)szLabel + " (" + strDrive +")"); 					
    				break;
    			default:
    				break;
    		}
        }
        dwDriveList >>= 1;
        nPos++;
    }
    

    }**

    2. This function should build the tree with all the icons :

    void CLeftView::InsertFileItem(const CString s

    N I 2 Replies Last reply
    0
    • C CrocodileBuck

      Hi ;), i coded a working treeview(SDI/Windows Explorer Style), but hardly without icons, there is shown only one icon in my treeview. Pic ;) : http://filehosting.at/images/download.php?file=b14ad20aa1a01412004995061e3202bb I want to show the original explorer icons in my treeview so i tried it with

      SHGetFileInfo()

      ...but it won't work :confused: Here is some sample code (i don't want to post too much): 1. This function detects the drives and labels :

      **void CLeftView::CreateRoots()
      {
      CString strMessage;
      int nPos = 65;
      CString strDrive;
      TCHAR szLabel[128];
      DWORD dwVolumeSerialNumber;
      DWORD dwMaxNameLength;
      DWORD dwFileSystemFlags;
      TCHAR szFileSysName[128];

      UINT	uDriveType;
      CString cstrWirDir;
      TCHAR	infoBuf\[INFO\_BUFFER\_SIZE\];
      DWORD	dwDriveList = GetLogicalDrives ();			// Anzahl der Laufwerke ermitteln
      

      //----------------------------------------------------------------------------------------------------------------

      GetWindowsDirectory(infoBuf, INFO\_BUFFER\_SIZE);
      cstrWirDir = infoBuf;
      cstrWirDir = cstrWirDir.GetAt(0);
      cstrWirDir = cstrWirDir + ":";
      

      //----------------------------------------------------------------------------------------------------------------

      while (dwDriveList) 
      {
          if (dwDriveList & 1) 
      	{
      		strDrive = "?:\\\\";
              strDrive.SetAt (0,nPos);
      		uDriveType = GetDriveType(strDrive);
      		
      		GetVolumeInformation (strDrive, szLabel,
      					          sizeof( szLabel ) - 1,
      							  &dwVolumeSerialNumber,
      							  &dwMaxNameLength,
      							  &dwFileSystemFlags,
      							  szFileSysName,
      							  sizeof( szFileSysName ) - 1);	
      		
      		switch(uDriveType)
      		{
      
      			// ToDo: Wenn kein Name für Diskettenlaufwerk(und andere), dann vorgefertigtes Label
      			case 2: // Diskettenlaufwerk
      				strDrive = strDrive.Left(2);
      				InsertFileItem("3½-Diskette (" + strDrive +")");
      				break;
      			case 3: // Festplatte
      				strDrive = strDrive.Left(2);
      				// AfxMessageBox(strDrive, MB\_OK);
      				InsertFileItem((CString)szLabel + " (" + strDrive +")");
      				break;
      			case 5: // CD-Rom
      				strDrive = strDrive.Left(2);
      				InsertFileItem((CString)szLabel + " (" + strDrive +")"); 					
      				break;
      			default:
      				break;
      		}
          }
          dwDriveList >>= 1;
          nPos++;
      }
      

      }**

      2. This function should build the tree with all the icons :

      void CLeftView::InsertFileItem(const CString s

      N Offline
      N Offline
      Nathan Holt at EMOM
      wrote on last edited by
      #2

      CrocodileBuck wrote:

      SHGetFileInfo(sFile, 0, &sfi, sizeof(SHFILEINFO),SHGFI_SYSICONINDEX | SHGFI_SMALLICON);

      When you create the tree control, you need to call SHGetFileInfo with SHGFI_SYSICONINDEX | SHGFI_SMALLICON, and get the return value, which is a handle to the system image list. You then need to set your tree view's small icon image list to be the system image list. After that, your tree view should show the right icons. The code would be something like this:

      HANDLE hSystemImageList = SHGetFileInfo(sKnownFile, 0, &sfi, sizeof(SHELLFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
      trCtrl.SetImageList(CImageList::FromHandle(hSystemImageList), TVSIL_NORMAL);

      Nathan

      C 1 Reply Last reply
      0
      • N Nathan Holt at EMOM

        CrocodileBuck wrote:

        SHGetFileInfo(sFile, 0, &sfi, sizeof(SHFILEINFO),SHGFI_SYSICONINDEX | SHGFI_SMALLICON);

        When you create the tree control, you need to call SHGetFileInfo with SHGFI_SYSICONINDEX | SHGFI_SMALLICON, and get the return value, which is a handle to the system image list. You then need to set your tree view's small icon image list to be the system image list. After that, your tree view should show the right icons. The code would be something like this:

        HANDLE hSystemImageList = SHGetFileInfo(sKnownFile, 0, &sfi, sizeof(SHELLFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
        trCtrl.SetImageList(CImageList::FromHandle(hSystemImageList), TVSIL_NORMAL);

        Nathan

        C Offline
        C Offline
        CrocodileBuck
        wrote on last edited by
        #3

        Hi Nathan ;), thanx for your quick reply. But when I try your 2 lines of code it won't work. There will not be any error message, there are simply no icons in the tree :( ! My coding skills aren't as good as yours! Perhaps, if it is not too much effort you could have a closer look to my code which i have uploaded and implement the code how and where it has to be? :) I really tried it to build up this view for 2 day's, i'm not too lazy i simply couldn't get it to work :doh: :sigh: :doh: Please help me :) Thank and best regards Crocodile Buck

        1 Reply Last reply
        0
        • C CrocodileBuck

          Hi ;), i coded a working treeview(SDI/Windows Explorer Style), but hardly without icons, there is shown only one icon in my treeview. Pic ;) : http://filehosting.at/images/download.php?file=b14ad20aa1a01412004995061e3202bb I want to show the original explorer icons in my treeview so i tried it with

          SHGetFileInfo()

          ...but it won't work :confused: Here is some sample code (i don't want to post too much): 1. This function detects the drives and labels :

          **void CLeftView::CreateRoots()
          {
          CString strMessage;
          int nPos = 65;
          CString strDrive;
          TCHAR szLabel[128];
          DWORD dwVolumeSerialNumber;
          DWORD dwMaxNameLength;
          DWORD dwFileSystemFlags;
          TCHAR szFileSysName[128];

          UINT	uDriveType;
          CString cstrWirDir;
          TCHAR	infoBuf\[INFO\_BUFFER\_SIZE\];
          DWORD	dwDriveList = GetLogicalDrives ();			// Anzahl der Laufwerke ermitteln
          

          //----------------------------------------------------------------------------------------------------------------

          GetWindowsDirectory(infoBuf, INFO\_BUFFER\_SIZE);
          cstrWirDir = infoBuf;
          cstrWirDir = cstrWirDir.GetAt(0);
          cstrWirDir = cstrWirDir + ":";
          

          //----------------------------------------------------------------------------------------------------------------

          while (dwDriveList) 
          {
              if (dwDriveList & 1) 
          	{
          		strDrive = "?:\\\\";
                  strDrive.SetAt (0,nPos);
          		uDriveType = GetDriveType(strDrive);
          		
          		GetVolumeInformation (strDrive, szLabel,
          					          sizeof( szLabel ) - 1,
          							  &dwVolumeSerialNumber,
          							  &dwMaxNameLength,
          							  &dwFileSystemFlags,
          							  szFileSysName,
          							  sizeof( szFileSysName ) - 1);	
          		
          		switch(uDriveType)
          		{
          
          			// ToDo: Wenn kein Name für Diskettenlaufwerk(und andere), dann vorgefertigtes Label
          			case 2: // Diskettenlaufwerk
          				strDrive = strDrive.Left(2);
          				InsertFileItem("3½-Diskette (" + strDrive +")");
          				break;
          			case 3: // Festplatte
          				strDrive = strDrive.Left(2);
          				// AfxMessageBox(strDrive, MB\_OK);
          				InsertFileItem((CString)szLabel + " (" + strDrive +")");
          				break;
          			case 5: // CD-Rom
          				strDrive = strDrive.Left(2);
          				InsertFileItem((CString)szLabel + " (" + strDrive +")"); 					
          				break;
          			default:
          				break;
          		}
              }
              dwDriveList >>= 1;
              nPos++;
          }
          

          }**

          2. This function should build the tree with all the icons :

          void CLeftView::InsertFileItem(const CString s

          I Offline
          I Offline
          Iain Clarke Warrior Programmer
          wrote on last edited by
          #4

          Lazy reply: Go check my article on detecting drives - it has code for showing drive icons, etc. And read the comments, where most of that information came from. Iain.

          Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.

          C 1 Reply Last reply
          0
          • I Iain Clarke Warrior Programmer

            Lazy reply: Go check my article on detecting drives - it has code for showing drive icons, etc. And read the comments, where most of that information came from. Iain.

            Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.

            C Offline
            C Offline
            CrocodileBuck
            wrote on last edited by
            #5

            Hi Mr. Clarke, i know your article, and it is very good. :-D I can show the drive letters and the lablels that's not the problem. I know how to detect the drives etc. The Problem is that i couldn't show the system icons.:confused: I think there is something wrong with my SytemImageList :(( , i think there are not enough icons in it, or not the right icons :sigh: ! Perhaps if you have a look at the small sample i have uploaded, it will take you only seconds to detect and terminate the mistake! Thanx for your quick reply :) best regards Crocodile Buck

            C 1 Reply Last reply
            0
            • C CrocodileBuck

              Hi Mr. Clarke, i know your article, and it is very good. :-D I can show the drive letters and the lablels that's not the problem. I know how to detect the drives etc. The Problem is that i couldn't show the system icons.:confused: I think there is something wrong with my SytemImageList :(( , i think there are not enough icons in it, or not the right icons :sigh: ! Perhaps if you have a look at the small sample i have uploaded, it will take you only seconds to detect and terminate the mistake! Thanx for your quick reply :) best regards Crocodile Buck

              C Offline
              C Offline
              CrocodileBuck
              wrote on last edited by
              #6

              I solved the Problem :) :-D :laugh: Best regards Crocodile Buck

              I 1 Reply Last reply
              0
              • C CrocodileBuck

                I solved the Problem :) :-D :laugh: Best regards Crocodile Buck

                I Offline
                I Offline
                Iain Clarke Warrior Programmer
                wrote on last edited by
                #7

                CrocodileBuck wrote:

                I solved the Problem

                Glad to hear it - I was just going through my emails, and had some spare time so was going to attack your code. What was the solution in the end? Iain.

                Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups