[RESOLVED] File Icon to Picture Control
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: [RESOLVED] File Icon to Picture Control

  1. #1
    Join Date
    May 2006
    Location
    beyond the pillars of hercules
    Posts
    295

    [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.

  2. #2
    Join Date
    Apr 1999
    Posts
    3,585

    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!

  3. #3
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    7,994

    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.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  4. #4
    Join Date
    May 2006
    Location
    beyond the pillars of hercules
    Posts
    295

    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);

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,011

    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

  6. #6
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    7,994

    Re: File Icon to Picture Control

    Quote Originally Posted by Cpp_Noob View Post
    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);
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  7. #7
    Join Date
    May 2006
    Location
    beyond the pillars of hercules
    Posts
    295

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center