yakky
asked on
SHGetFileInfo
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:\\wind ows\\reged it.exe",0, &shfi,size of(SHFILEI NFO),SHGFI _ICONLOCAT ION))
{
CString me = (char*)shfi.szDisplayName;
TRACE("Succeded getting icon path
from .exe*%s*\n",me);
}
else
{
TRACE("FAILED\n");
}
Thanks in advance
Ian Robertson
SHFILEINFO shfi;
if(SHGetFileInfo("c:\\wind
{
CString me = (char*)shfi.szDisplayName;
TRACE("Succeded getting icon path
from .exe*%s*\n",me);
}
else
{
TRACE("FAILED\n");
}
Thanks in advance
Ian Robertson
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 ?
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 ?
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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:\\wind ows\\reged it.exe",0, &shfi,size of(SHFILEI NFO),SHGFI _ICON))
{
hGen32Icon = shfi.hIcon;
TRACE("1Succeded getting icon from .exe\n");
DrawIcon(ianDC,0,0,hGen32I con);
GetMenu()->SetMenuItemBitm aps( IDM_ONE, MF_ENABLED,ian,NULL);
}
Ive tried papirus suggestion and nothing happens what am I doing wrong.
HICON hGen32Icon;
SHFILEINFO shfi;
CBitmap *ian = new CBitmap;
HDC ianDC=::CreateCompatibleDC
if(SHGetFileInfo("c:\\wind
{
hGen32Icon = shfi.hIcon;
TRACE("1Succeded getting icon from .exe\n");
DrawIcon(ianDC,0,0,hGen32I
GetMenu()->SetMenuItemBitm
}
try this :
CBitmap Bmp ;
CDC MemDC ;
MemDC.CreateCompatibleDC(N ULL) ;
Bmp.CreateCompatibleBitmap (&MemDC,32 ,32) ;
MemDC.SelectObject(&Bmp) ;
::DrawIcon(MemDC.m_hDC,0,0 ,hIcon) ;
....
CBitmap Bmp ;
CDC MemDC ;
MemDC.CreateCompatibleDC(N
Bmp.CreateCompatibleBitmap
MemDC.SelectObject(&Bmp) ;
::DrawIcon(MemDC.m_hDC,0,0
....
ASKER
It Almost works however, Ive lost the color.
Can you suggest how to get the color back?
Can you suggest how to get the color back?
CBitmap Bmp ;
CDC MemDC ;
CDC *pWndDC = AfxGetMainWnd()->GetDC() ;
if (pWndDC)
{
MemDC.CreateCompatibleDC(p WndDC) ;
Bmp.CreateCompatibleBitmap (&pWndDC,3 2,32) ;
MemDC.SelectObject(&Bmp) ;
::DrawIcon(MemDC.m_hDC,0,0 ,hIcon) ;
AfxGetMainWnd()->ReleaseDC (pWndDC) ;
}
CDC MemDC ;
CDC *pWndDC = AfxGetMainWnd()->GetDC() ;
if (pWndDC)
{
MemDC.CreateCompatibleDC(p
Bmp.CreateCompatibleBitmap
MemDC.SelectObject(&Bmp) ;
::DrawIcon(MemDC.m_hDC,0,0
AfxGetMainWnd()->ReleaseDC
}
ASKER
Thanks very much, youve done an excellent job. Im very grateful.
Yours sincerely
Ian Robertson
Yours sincerely
Ian Robertson
You are always wellcome.
Gena Pergament
Gena Pergament