Solved

SHGetFileInfo

Posted on 1997-05-15
10
854 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

15 Experts available now in Live!

Get 1:1 Help Now