Solved

SHGetFileInfo

Posted on 1997-05-15
10
855 Views
Last Modified: 2013-11-19
Heres my problem, Im trying to get the path/filename to the icon from  an .exe file. Can any one modify the following bit of code to do this (since it doesnt work at the moment).

SHFILEINFO shfi;
if(SHGetFileInfo("c:\\windows\\regedit.exe",0,&shfi,sizeof(SHFILEINFO),SHGFI_ICONLOCATION))
{
CString me = (char*)shfi.szDisplayName;
TRACE("Succeded getting icon path  
from .exe*%s*\n",me);
}
else
{
TRACE("FAILED\n");
}

Thanks in advance
Ian Robertson
0
Comment
Question by:yakky
  • 4
  • 4
  • 2
10 Comments
 
LVL 4

Expert Comment

by:mbhakta
ID: 1301570
SHGFI_ICONLOCATION only gets the display name of the application as it appears from on the desktop. Can you make it clear why would you like to get the filename of the icon ?
0
 
LVL 4

Expert Comment

by:mbhakta
ID: 1301571
SHGFI_ICONLOCATION only gets the display name of the application as it appears from on the desktop. Can you make it clear why would you like to get the filename of the icon ?
0
 

Author Comment

by:yakky
ID: 1301572
I have a program which converts a filename of an icon into a bitmap. I was hoping to use SHGetFileInfo (SHGFI_ICONLOCATION) because according to the documentation it retrieves and I quote "The name of the file that contains the icon representing the file. The name is copied to the szDisplayName member of the structure specified by psfi".

That is why I would like to be able to get hold of a programs, associated icon's filename.

Alternatively could someone tell me how to convert a HICON to a CBitmap.
Thanks again
Ian
0
 
LVL 1

Accepted Solution

by:
papirus earned 100 total points
ID: 1301573
to convert HICON into CBitmap :

Create a memory DC, create a bitmap, select this bitmap in DC,
call DrawIcon-function, than you'll have in this created bitmap the icon's image.
0
 

Author Comment

by:yakky
ID: 1301574
Ok I dont know that much about MFC/windows calls
Ive tried papirus suggestion and nothing happens what am I doing wrong.


HICON hGen32Icon;
SHFILEINFO shfi;
CBitmap *ian = new CBitmap;
HDC ianDC=::CreateCompatibleDC(NULL);

if(SHGetFileInfo("c:\\windows\\regedit.exe",0,&shfi,sizeof(SHFILEINFO),SHGFI_ICON))
{
      hGen32Icon = shfi.hIcon;
TRACE("1Succeded getting icon from .exe\n");
      DrawIcon(ianDC,0,0,hGen32Icon);
      GetMenu()->SetMenuItemBitmaps( IDM_ONE, MF_ENABLED,ian,NULL);

}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:papirus
ID: 1301575
try this :

CBitmap Bmp ;
CDC MemDC  ;

MemDC.CreateCompatibleDC(NULL) ;
Bmp.CreateCompatibleBitmap(&MemDC,32,32) ;
MemDC.SelectObject(&Bmp) ;
::DrawIcon(MemDC.m_hDC,0,0,hIcon) ;

....

0
 

Author Comment

by:yakky
ID: 1301576
It Almost works however, Ive lost the color.
Can you suggest how to get the color back?
0
 
LVL 1

Expert Comment

by:papirus
ID: 1301577
CBitmap Bmp ;
CDC MemDC ;
CDC *pWndDC = AfxGetMainWnd()->GetDC() ;
if (pWndDC)
{
      MemDC.CreateCompatibleDC(pWndDC) ;
      Bmp.CreateCompatibleBitmap(&pWndDC,32,32) ;
      MemDC.SelectObject(&Bmp) ;
      ::DrawIcon(MemDC.m_hDC,0,0,hIcon) ;
      AfxGetMainWnd()->ReleaseDC(pWndDC) ;
}
0
 

Author Comment

by:yakky
ID: 1301578
Thanks very much, youve done an excellent job. Im very grateful.
Yours sincerely
Ian Robertson
0
 
LVL 1

Expert Comment

by:papirus
ID: 1301579
You are always wellcome.

Gena Pergament
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 51
how to monitor remote shell execution on linux 9 97
sumDigits challenge 9 123
post4 challenge 28 93
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now