Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Overlay Icons? (Like shortcut icons)

3 views
Skip to first unread message

B Pilgrim

unread,
May 11, 2003, 6:23:03 PM5/11/03
to
I'd like to put a small image on top of an icon, just like windows puts a
black arrow in a white box in the lower left corner of shortcut icons.
One way of doing this would be to load the icon in a picturebox, draw the
other picture on top, save as bmp and convert to icon. Is there any easier
way to use overlay icons? Can I use API to display an icon with overlay
picture without having to create a third icon?


Mike D Sutton

unread,
May 11, 2003, 7:19:06 PM5/11/03
to

Sure, do the same as Window's does and just draw the small (shortcut) icon
ontop of the main one.
You'll find the shortcut icon for instance in Shell32.dll and can extract it
with ExtractIconEx() if you need it. Here's an old post as an example:
http://groups.google.co.uk/groups?selm=eFqwYLGnCHA.2200%40TK2MSFTNGP10
You can also create your own icon's at runtime in memory but it's a much
more complicated process, here's another old post demonstrating that:
http://groups.google.com/groups?selm=uc8gAJcuCHA.2448%40TK2MSFTNGP10
Hope this helps,

Mike


-- EDais --

- Microsoft Visual Basic MVP -
WWW: Http://www20.brinkster.com/EDais/
Work E-Mail: ED...@btclick.com
Other E-Mail: Mike....@btclick.com


Grinder

unread,
May 11, 2003, 10:21:07 PM5/11/03
to

"B Pilgrim" <exkalib...@yahoo.se> wrote in message
news:b3Ava.5643$mU6....@newsb.telia.net...

The ImageList has an overlay method that can be used to
generate new images by combining existing ones -- perhaps that
would be of use?


B Pilgrim

unread,
May 11, 2003, 11:03:53 PM5/11/03
to

"Mike D Sutton" <Mike....@btclick.com> skrev i meddelandet
news:euaQHNBG...@tk2msftngp13.phx.gbl...

> > I'd like to put a small image on top of an icon, just like windows puts
a
> > black arrow in a white box in the lower left corner of shortcut icons.
> > One way of doing this would be to load the icon in a picturebox, draw
the
> > other picture on top, save as bmp and convert to icon. Is there any
easier
> > way to use overlay icons? Can I use API to display an icon with overlay
> > picture without having to create a third icon?
>
> Sure, do the same as Window's does and just draw the small (shortcut) icon
> ontop of the main one.
> You'll find the shortcut icon for instance in Shell32.dll and can extract
it
> with ExtractIconEx() if you need it. Here's an old post as an example:
> http://groups.google.co.uk/groups?selm=eFqwYLGnCHA.2200%40TK2MSFTNGP10
> You can also create your own icon's at runtime in memory but it's a much
> more complicated process, here's another old post demonstrating that:
> http://groups.google.com/groups?selm=uc8gAJcuCHA.2448%40TK2MSFTNGP10
> Hope this helps,
>

Thanks, it was simpler than expected. Now I only have to figure out how to
extract 16x16 icons. For some reason ExtractIconEx() only returns 32x32
icons from Shell32.dll. Are small system icons stored somewhere else?


B Pilgrim

unread,
May 11, 2003, 11:23:51 PM5/11/03
to
"Grinder" <gri...@no.spam.maam.com> skrev i meddelandet
news:%23fpHn0C...@TK2MSFTNGP12.phx.gbl...

Sorry Grinder. Sent a direct mail by mistake. Here it is again.

Do you happen to know how to use it? I'm not all that familiar with image
lists.
The syntax is "imagelist1.Overlay(Key1, Key2) As lPictureDisp". I'm guessing
Key1 and Key2 is the identifiers for the images to be merged. Would
something like this work?

Picture1.Image = imagelist1.Overlay(Key1, Key2)


Grinder

unread,
May 11, 2003, 11:56:12 PM5/11/03
to
More like:

Set Picture1.Picture = imagelist1.Overlay(Key1, Key2)

Grinder

unread,
May 11, 2003, 11:56:37 PM5/11/03
to
I recommended this because I thought you might already be using
imagelists.


Mike D Sutton

unread,
May 12, 2003, 9:30:07 AM5/12/03
to
> Thanks, it was simpler than expected. Now I only have to figure out how to
> extract 16x16 icons. For some reason ExtractIconEx() only returns 32x32
> icons from Shell32.dll. Are small system icons stored somewhere else?

The ExtractIconEx() call can the small and/or large icon lists. To do so in
the previous code, just change the ExtractIconEx() call to the following:

'***
Call ExtractIconEx(FilePath, 0, ByVal 0&, LargeIcons(0), NumIcon)
'***

And remove the DI_DEFAULTSIZE flag from the DrawIconEx() call.

B Pilgrim

unread,
May 12, 2003, 12:45:18 PM5/12/03
to
"Grinder" <gri...@no.spam.maam.com> skrev i meddelandet
news:uVsT%23pDGD...@TK2MSFTNGP12.phx.gbl...

> I recommended this because I thought you might already be using
> imagelists.

Yes, I'm going to build a program with an explorer type interface. As I
understand it, image lists are necessary in order to populate a listview
with icons. Still I'm not sure how to use the overlay function when binding
the image list to the listview, but I'll look into it. Thanks for the tip.


B Pilgrim

unread,
May 12, 2003, 2:03:15 PM5/12/03
to
"Mike D Sutton" <Mike....@btclick.com> skrev i meddelandet
news:b9o7kv$kt3$1...@hercules.btinternet.com...

> > Thanks, it was simpler than expected. Now I only have to figure out how
to
> > extract 16x16 icons. For some reason ExtractIconEx() only returns 32x32
> > icons from Shell32.dll. Are small system icons stored somewhere else?
>
> The ExtractIconEx() call can the small and/or large icon lists. To do so
in
> the previous code, just change the ExtractIconEx() call to the following:
>
> '***
> Call ExtractIconEx(FilePath, 0, ByVal 0&, LargeIcons(0), NumIcon)
> '***
>
> And remove the DI_DEFAULTSIZE flag from the DrawIconEx() call.
> Hope this helps,

It sure did. For anyone who is interested, here is an example on how to
extract large and small icon from winzip (winzip must be installed on the
system).

Put two PictureBoxes on a form. Set AutoRedraw property to True for both of
them. Add the following code to the form.

<VB>

Const DI_MASK = &H1
Const DI_IMAGE = &H2
Const DI_NORMAL = DI_MASK Or DI_IMAGE
Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias
"ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String,
lpiIcon As Long) As Long
Private Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal
xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As
Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal
hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As
Long
Private Declare Function ExtractIconEx Lib "shell32.dll" Alias
"ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long,
phiconLarge As Long, phiconSmall As Long, ByVal nIcons As Long) As Long

Private Sub Form_Paint()
Dim SmallIcon As Long
Dim LargeIcon As Long

ExtractIconEx "c:\program\winzip\winzip32.exe", 0, LargeIcon, SmallIcon,
1

DrawIconEx Picture1.hdc, 0, 0, SmallIcon, 0, 0, 0, 0, DI_NORMAL
DrawIconEx Picture2.hdc, 0, 0, LargeIcon, 0, 0, 0, 0, DI_NORMAL

DestroyIcon SmallIcon
DestroyIcon LargeIcon
End Sub

</VB>


B Pilgrim

unread,
May 12, 2003, 2:08:17 PM5/12/03
to
The declaration of ExtractAssociatedIcon can be removed.
0 new messages