Thread View: borland.public.cppbuilder.nativeapi
9 messages
9 total messages
Started by remmurds
Sun, 02 Dec 2007 00:26
Get the icon by using "SHGetFileInfo"...
Author: remmurds
Date: Sun, 02 Dec 2007 00:26
Date: Sun, 02 Dec 2007 00:26
15 lines
1375 bytes
1375 bytes
Hi all, I use "SHGetFileInfo" to get the large icon from a file or dir and show it on an Image component: SHFILEINFO info; ImageList->Handle = SHGetFileInfo(FileName.c_str(), 0, &info, sizeof(info), SHGFI_LARGEICON | SHGFI_SYSICONINDEX); ImageList->ShareImages = true; ImageList->GetIcon(info.iIcon, ImageIco->Picture->Icon); But however the icon which i get is only 32*32 pixels, not the original 48*48, How do I get it? Thank you :)
Re: Get the icon by using "SHGetFileInfo"...
Author: Asger Joergensen
Date: Sun, 02 Dec 2007 17:34
Date: Sun, 02 Dec 2007 17:34
39 lines
2137 bytes
2137 bytes
Hi remmurds
remmurds says:
>
> But however the icon which i get is only 32*32 pixels, not the original
> 48*48, How do I get it?
According to the help file:
SHGFI_ICON
Retrieves the handle of the icon that represents the file
and the index of the icon within the system image list.
The **handle** is copied to the **hIcon** member of the
structure specified by psfi, and the index is copied to
the iIcon member.
The return value is the handle of the system image list.
It looks like You have to deal with the hIcon handle
and then use the:
DrawIconEx(
HDC hdc, // handle to device context
int xLeft, // x-coordinate of upper left corner
int yTop, // y-coordinate of upper left corner
HICON hIcon, // handle to icon to draw
int cxWidth, // width of the icon
int cyWidth, // height of the icon
UINT istepIfAniCur, // index of frame in animated cursor
HBRUSH hbrFlickerFreeDraw, // handle to background brush
UINT diFlags // icon-drawing flags
);
To draw the Icon.
Let me know if it works, I haven't tryed it.
Kind regards
Asger
Re: Get the icon by using "SHGetFileInfo"...
Author: remmurds
Date: Sun, 02 Dec 2007 18:40
Date: Sun, 02 Dec 2007 18:40
55 lines
2651 bytes
2651 bytes
Thank you for your response :) I try to use this function to get the icon: SHGetFileInfo(FileName.c_str(), 0, &info, sizeof(info), SHGFI_LARGEICON | SHGFI_SYSICONINDEX); DrawIconEx(ImageIco->Canvas->Handle, 0, 0, info.hIcon, 48, 48, 0, 0, DI_NORMAL | DI_COMPAT); But it doesn't work. Do I use it with incorrect parameters? "Asger Joergensen" <junk@Asger-P.dk> ���g��l��s�D:MPG.21bd0b1963f2bda698992f@newsgroups.borland.com... > > Hi remmurds > > remmurds says: >> >> But however the icon which i get is only 32*32 pixels, not the original >> 48*48, How do I get it? > > According to the help file: > SHGFI_ICON > Retrieves the handle of the icon that represents the file > and the index of the icon within the system image list. > The **handle** is copied to the **hIcon** member of the > structure specified by psfi, and the index is copied to > the iIcon member. > The return value is the handle of the system image list. > > It looks like You have to deal with the hIcon handle > > and then use the: > > DrawIconEx( > HDC hdc, // handle to device context > int xLeft, // x-coordinate of upper left corner > int yTop, // y-coordinate of upper left corner > HICON hIcon, // handle to icon to draw > int cxWidth, // width of the icon > int cyWidth, // height of the icon > UINT istepIfAniCur, // index of frame in animated cursor > HBRUSH hbrFlickerFreeDraw, // handle to background brush > UINT diFlags // icon-drawing flags > ); > > To draw the Icon. > > Let me know if it works, I haven't tryed it. > > Kind regards > Asger
Re: Get the icon by using "SHGetFileInfo"...
Author: Asger Joergensen
Date: Sun, 02 Dec 2007 19:33
Date: Sun, 02 Dec 2007 19:33
45 lines
2057 bytes
2057 bytes
Hi remmurds
remmurds says:
> Thank you for your response :)
>
> I try to use this function to get the icon:
>
>
> SHGetFileInfo(FileName.c_str(), 0, &info, sizeof(info), SHGFI_LARGEICON |
> SHGFI_SYSICONINDEX);
> DrawIconEx(ImageIco->Canvas->Handle, 0, 0, info.hIcon, 48, 48, 0, 0,
> DI_NORMAL | DI_COMPAT);
>
>
> But it doesn't work.
> Do I use it with incorrect parameters?
Do You check if the the handle is different from NULL ?
According to the helpfile SHGFI_ICON is the one
that will retrieve the handle to the icon the other
SHGFI_LARGEICON go for a specific size and You don't
need the index.
This would be my suggestion:
DWORD Res = SHGetFileInfo(FileName.c_str(), 0, &info, sizeof(info), SHGFI_ICON);
if( ! Res){// GetLastError}
if(info.hIcon)
{
if( ! DrawIconEx(ImageIco->Canvas->Handle, 0, 0, info.hIcon, 48, 48, 0, 0,
DI_NORMAL) )
{// GetLastError}
}
by the way what is ImageIco ?
is it a TImage ?
Have You remembered to set the size of ImageIco ?
Kind regards
Asger
Re: Get the icon by using "SHGetFileInfo"...
Author: remmurds
Date: Sun, 02 Dec 2007 23:40
Date: Sun, 02 Dec 2007 23:40
50 lines
2392 bytes
2392 bytes
"Asger Joergensen" <junk@Asger-P.dk> ���g��l��s�D:MPG.21bd27055e96426f989930@newsgroups.borland.com...
>
> Hi remmurds
>
> Do You check if the the handle is different from NULL ?
>
> According to the helpfile SHGFI_ICON is the one
> that will retrieve the handle to the icon the other
> SHGFI_LARGEICON go for a specific size and You don't
> need the index.
>
> This would be my suggestion:
>
> DWORD Res = SHGetFileInfo(FileName.c_str(), 0, &info, sizeof(info),
> SHGFI_ICON);
>
> if( ! Res){// GetLastError}
>
> if(info.hIcon)
> {
>
> if( ! DrawIconEx(ImageIco->Canvas->Handle, 0, 0, info.hIcon, 48, 48, 0, 0,
> DI_NORMAL) )
> {// GetLastError}
> }
>
> by the way what is ImageIco ?
> is it a TImage ?
> Have You remembered to set the size of ImageIco ?
>
> Kind regards
> Asger
Oh, sorry about that.
I forgot to explain that ImageIco is a TImage component :)
The size of ImageIcon is 48*48, the "Transparent" and "Stretch" property is
false;
Now I can draw the icon with this codes:
SHGetFileInfo(FileName.c_str(), 0, &info, sizeof(info), SHGFI_ICON);
DrawIconEx(ImageIco->Canvas->Handle, 0, 0, info.hIcon, 48, 48, 0, 0,
DI_NORMAL);
Mmm...but it looks like a smaller picture "zoom out" to 48*48 with "Mosaic",
even the original icon is 48*48(I made it for testing).
I will keep trying. Thank you for your suggestion : )
Re: Get the icon by using "SHGetFileInfo"...
Author: Asger Joergensen
Date: Mon, 03 Dec 2007 01:04
Date: Mon, 03 Dec 2007 01:04
19 lines
1583 bytes
1583 bytes
Hi remmurds I just came to think that this might not be the right function for what You want to do. SHGetFileInfo is as far as I know used when You want to retrieve systeminformation about a file ant it is therefor the function retrieves the information You can see in Your explorer. In other words if Your system shows 32x32 icons that is what You get when You call SHGetFileInfo. If you want to draw an Icon then You have to load the actual Icon either from resource or from file. *** I think **** ;-) Kind regards Asger
Re: Get the icon by using "SHGetFileInfo"...
Author: Remy Lebeau (TeamB)
Date: Mon, 03 Dec 2007 19:57
Date: Mon, 03 Dec 2007 19:57
20 lines
1471 bytes
1471 bytes
"Asger Joergensen" <junk@Asger-P.dk> wrote in message
news:MPG.21bd0b1963f2bda698992f@newsgroups.borland.com...
> It looks like You have to deal with the hIcon handle
>
> and then use the:
>
> DrawIconEx(
You don't need DrawIconEx(). Simply assign to the returned HICON to TIcon's
Handle property instead.
SHFILEINFO info;
if( SHGetFileInfo(FileName.c_str(), 0, &info, sizeof(info), SHGFI_ICON |
SHGFI_LARGEICON) )
ImageIco->Picture->Icon->Handle = info.hIcon;
Gambit
Re: Get the icon by using "SHGetFileInfo"...
Author: Asger Joergensen
Date: Mon, 03 Dec 2007 23:15
Date: Mon, 03 Dec 2007 23:15
33 lines
1962 bytes
1962 bytes
Hi Remy Remy Lebeau (TeamB) says: > > "Asger Joergensen" <junk@Asger-P.dk> wrote in message > news:MPG.21bd0b1963f2bda698992f@newsgroups.borland.com... > > > It looks like You have to deal with the hIcon handle > > > > and then use the: > > > > DrawIconEx( > > You don't need DrawIconEx(). Simply assign to the returned HICON to TIcon's > Handle property instead. > > SHFILEINFO info; > if( SHGetFileInfo(FileName.c_str(), 0, &info, sizeof(info), SHGFI_ICON | > SHGFI_LARGEICON) ) > ImageIco->Picture->Icon->Handle = info.hIcon; Yea, I know I can do that, but we were trying to get the Icon in 48x48 and not 32x32, so by not specifying SHGFI_LARGEICON, I was hoping for a handle to an Icon containing all the sizes.;-) But as I mention in my last post, I don't think this is the way if the system is showing 32x32 icons. Never got a reply on that one. Kind regards Asger
Re: Get the icon by using "SHGetFileInfo"...
Author: Remy Lebeau (TeamB)
Date: Tue, 04 Dec 2007 01:00
Date: Tue, 04 Dec 2007 01:00
16 lines
1536 bytes
1536 bytes
"Asger Joergensen" <junk@Asger-P.dk> wrote in message news:MPG.21beac6b19b49f6b989934@newsgroups.borland.com... > Yea, I know I can do that, but we were trying > to get the Icon in 48x48 and not 32x32 SHGetFileInfo() does not support that icon size. Use LoadImage() instead. > by not specifying SHGFI_LARGEICON, I was hoping > for a handle to an Icon containing all the sizes.;-) That is not how SHGetFileInfo() works. Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads