-
April 2nd, 2009, 07:44 AM
#1
[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.
-
April 2nd, 2009, 07:54 AM
#2
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?
Gort...Klaatu, Barada Nikto!
-
April 2nd, 2009, 08:02 AM
#3
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.
-
April 2nd, 2009, 08:12 AM
#4
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);
-
April 2nd, 2009, 08:23 AM
#5
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?
Victor Nijegorodov
-
April 2nd, 2009, 08:29 AM
#6
Re: File Icon to Picture Control
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);
-
April 2nd, 2009, 08:34 AM
#7
Re: File Icon to Picture Control
thank you for you help ovidiucucu !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|