Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GIFs nd ICONs 2

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
I want to be able to display a gif as the icon for a form.

Is theer an easy way to do this?

Can anyone suggest any code or componets that will convert a GIF into an ICO or BMP?

Cheers,

elziko
 
elziko,
they have a nifty little program called any to icon at I use it for all my icon needs

hth
Scoty ::)
"Learn from others' mistakes. You could not live long enough to make them all yourself."
-- Hyman George Rickover (1900-86),
 
Hi Scoty and elziko,

Thanks to the second for the question and for the first for the url.
It will be of great help the next time i need that conversion.

good work ===================
* Marta Oliveira *
===================
marta100@aeiou.pt
-------------------
CPC_TA- Braga
-------------------
Portugal
===================
 
And here's my attempt at much the same thing (obviously there's some cheating going on...). As ever from me, this is an illustrative example, and is missing niceties such as error checking:

' Returns a 32 * 32 windows icon from any of the following picture sources: .ICO .CUR .JPG .BMP .GIF
' Optionally specify the size of the returned icon
Public Function GetIconFromImage(strImage As String, Optional width As Long = 32, Optional height As Long = 32) As Picture
Dim il As Object

' Leverage the ImageList control
Set il = CreateObject("MSComCtlLib.imagelistctrl")
il.ImageWidth = width
il.ImageHeight = height
il.ListImages.Add , , LoadPicture(strImage)
Set GetIconFromImage = il.ListImages(1).ExtractIcon ' The magic bit. Make the control do all the work for you
' Clean up
Set il = Nothing
End Function
 
A couple of minor notes worth adding.

Firstly, PaintPicture knows how to paint 'icons' correctly, with transparency (for years programmers have used a set of API calls involving creating memory and device compatible DCs along with various bitblits with appropriate ROPS applied to achieve this). So, by selecting the ListImages mask color and setting the UseMaskColor setting, we can easily paint pictures with transparent areas with zero additional effort.

Secondly, for those programmers who still want handles to the masked and unmasked bitmap handles for a given source, they can be very quickly determined by using something similar to the following:

Private Declare Function GetIconInfo Lib "user32" (ByVal hIcon As Long, piconinfo As ICONINFO) As Long
Private Type ICONINFO
fIcon As Long
xHotspot As Long
yHotspot As Long
hbmMask As Long
hbmColor As Long
End Type

' Assumes ListImage is still loaded with our image as shown in previous example
public function GethMask() as long
Dim iconic As ICONINFO

Form1.PaintPicture ImageList1.ListImages(1).ExtractIcon, 0, 0
GetIconInfo ImageList1.ListImages(1).ExtractIcon, iconic
GethMask=iconic.hbmIcon
' iconic.hbmColor contains handle to unmasked bitmap
end function


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top