Only one Icon in my treeview!
-
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
-
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
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
-
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
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
-
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
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.
-
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.
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
-
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
I solved the Problem :) :-D :laugh: Best regards Crocodile Buck
-
I solved the Problem :) :-D :laugh: Best regards Crocodile Buck
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.