Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SHGetFileInfo

Posted on 1997-05-15
10
Medium Priority
?
863 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
papirus earned 200 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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

636 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