[RESOLVED] File Icon to Picture Control
im using this code to load the icon of a file , how can i display this icon into a Picture Control?
(code from http://weseetips.com/2008/06/03/how-...con-of-a-file/)
Code:
CString FilePath = _T("C:\\FooBar.zip");
// Get the file icon.
SHFILEINFO FileInfo = { 0 };
SHGetFileInfo( FilePath,
0,
&FileInfo,
sizeof( FileInfo ),
SHGFI_ICON );
// FileInfo.hIcon contains Icon handle.
Re: File Icon to Picture Control
Depending on the intended result, I would recommend you first load the icon into an image list. Can you provide more details on what you are trying to achieve?
Re: File Icon to Picture Control
Code:
((CStatic*)GetDlgItem(IDC_STATIC_TEST))->SetIcon(FileInfo.hIcon);
Do not forget (in the resource editor) to set for the picture control "Icon" type and to change IDC_STATIC identifier whit another one.
Re: File Icon to Picture Control
ah icon is not loading , i have set the Type of the picture control to "Icon"
Code:
CString FilePath;
SHFILEINFO FileInfo = { 0 };
CFileDialog CommonDialog(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("Executable Files (*.exe)|*.exe||"), NULL);
if(CommonDialog.DoModal() == IDOK)
{
FilePath = CommonDialog.GetPathName();
}
SHGetFileInfo( FilePath,0,&FileInfo,sizeof( FileInfo ),SHGFI_ICON );
(CStatic*)m_FileInfo_Dlg.GetDlgItem(IDC_ICON)->SetIcon(FileInfo.hIcon,false);
Re: File Icon to Picture Control
1. What is the return value of SHGetFileInfo?
2. What is the value of FileInfo.hIcon you are trying to set to the picture control?
3. Why don't you want to use ExtractIcon (or ExtractIconEx) API to load an icon from executable file?
Re: File Icon to Picture Control
Quote:
Originally Posted by
Cpp_Noob
Code:
(CStatic*)m_FileInfo_Dlg.GetDlgItem(IDC_ICON)->SetIcon(FileInfo.hIcon,false);
You have called CWnd::SetIcon and not CStatic::SetIcon
Take a more careful look at...
Code:
((CStatic*)GetDlgItem(IDC_STATIC_TEST))->SetIcon(FileInfo.hIcon);
...which is a little bit different.
Or, to write a little bit clearer
Code:
CStatic* pStatic = (CStatic*)GetDlgItem(IDC_STATIC_TEST);
pStatic->SetIcon(FileInfo.hIcon);
Re: File Icon to Picture Control
thank you for you help ovidiucucu ! :)