CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2000
    Location
    America
    Posts
    130

    More Icon Questions...Registry Related

    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?


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: More Icon Questions...Registry Related

    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
    [email protected]

    The best way to escape a problem, is to solve it.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Feb 2000
    Location
    America
    Posts
    130

    Re: More Icon Questions...Registry Related

    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.


  4. #4
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: More Icon Questions...Registry Related

    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
    [email protected]

    The best way to escape a problem, is to solve it.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  5. #5
    Join Date
    Feb 2000
    Location
    America
    Posts
    130

    Re: More Icon Questions...Registry Related

    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


  6. #6
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: More Icon Questions...Registry Related

    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...&sb=&category=

    Tom Cannaerts
    [email protected]

    The best way to escape a problem, is to solve it.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured