Click to See Complete Forum and Search --> : More Icon Questions...Registry Related


Atlantisoft
February 22nd, 2000, 08:17 AM
My program changes the registry key ".mp3". i want it's "DefaulIcon" key to be an icon in my exe. Normally i'd put the path of my program \ the name of my program & .exe but now my program uses a resource file for multiple icons. How do i tell it to use one of THOSE icons instead of the icon displayed on the exe itself?

Cakkie
February 22nd, 2000, 11:30 PM
In the registry key, supply the path to the exefilefollowed by a comma, and then the index number of the icon (you can get this by opening it in an icon vieuwer.

eg: c:\myMp3Player\myMp3Player.exe,2
This will select the icon with index 2

Tom Cannaerts
slisse@planetinternet.be

The best way to escape a problem, is to solve it.

Atlantisoft
February 23rd, 2000, 06:21 AM
how do i tell which icon is set to which index? and how can i display these at runtime? i have no clue how to use this resource file.

Cakkie
February 24th, 2000, 12:02 AM
This uses an API:


' paste this code in a new module
private type PicBmp
size as long
tType as long
hBmp as long
Reserved as long
end type

private Type GUID
Data1 as long
Data2 as Integer
Data3 as Integer
Data4(7) as byte
end type

private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc as PicBmp, RefIID as GUID, byval fPictureOwnsHandle as Long, IPic as IPicture) 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 Declare Function DestroyIcon Lib "user32" (byval _hicon as Long) as Long
public Function GetIconFromFile(FileName as string, IconIndex as Long, UseLargeIcon as Boolean) as Picture

Dim hsmallicon as Long
Dim selhandle as Long

Dim IPic as IPicture
Dim IID_IDispatch as GUID

If ExtractIconEx(FileName, IconIndex, hlargeicon, _hsmallicon, 1) > 0 then

If UseLargeIcon then
selhandle = hlargeicon
else
selhandle = hsmallicon
End If

With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0.Data4(7) = &H46
End With
With pic
.Size = len(pic)
.tType = vbPicTypeIcon
.hBmp = selhandle
End With
Call OleCreatePictureIndirect(pic, IID_IDispatch, 1, IPic)
object.set GetIconFromFile = IPicDestroyIcon hsmallicon
DestroyIcon hlargeicon

End If

End Function




This goes in a new form

' Create a form and add 2 pictureboxes and 2 buttons
' command1 will be the next button, command 2 the previous
' also add a label

Dim IconIndex as Long

private Sub form Load()
IconIndex = 0
ShowIcons
End Sub

private Sub ShowIcons()
' the last parameter (true or false) specifies whether to use the
' large icon (true) or the small (false)
Picture1.Picture = GetIconFromFile("your-icon-file-here",IconIndex,true)
Picture2.Picture = GetIconFromFile("your-icon-file-here",IconIndex,false)
label1.caption = "This is the icon with index: " & IconIndex
End Sub

private sub Command1_click()
' next
IconIndex = IconIndex + 1
ShowIcons
End Sub

private sub Command2_click()
' previous
IconIndex = IconIndex - 1
ShowIcons
End Sub



When running the program, you can scroll trough the icon file, while the index is shown in the label

Tom Cannaerts
slisse@planetinternet.be

The best way to escape a problem, is to solve it.

Atlantisoft
February 24th, 2000, 07:24 AM
Will this only work if i have the file on the Hard Drive? I need to have the resource file in my vb project when i call on it. The code you gave me calls on the file, but is there a way to tell it the file in my vb project? Thanx

Cakkie
February 24th, 2000, 11:19 PM
You can add icon to your program by using a *.res file, more info about this can be found in another post on this board, http://codeguru.developer.com/bbs/wt/showpost.pl?Board=vb&Number=15805&page=&view=&sb=&category=

Tom Cannaerts
slisse@planetinternet.be

The best way to escape a problem, is to solve it.