Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Sep 11, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Build a simple browser for icons

Winodws uses a special browser to show all icons contained in a file and offers the end user the possibility to choose an icon from it. You can add this functionallity to your applications through an undocumented API function, SHChangeIconDialog. Its Declare is:

Declare Function SHChangeIconDialog Lib "shell32" Alias "#62" (ByVal hOwner As _
    Long, ByVal szFilename As String, ByVal Reserved As Long, _
    lpIconIndex As Long) As Long
The first argument is the dialog owner: you can specify 0 for desktop, in order to make it a top-level window. The second argument is the file that is initially displayed and opened. I didn't find a use for the third argument, so you should consider it as "reserved" and always pass zero to it. Finally, the last argument is the index of the icon that will be selected when the dialog is opened.

The function returns 0 if the dialog is cancelled and non-zero in all other cases. When the function returns it stores the index of the selected incon in the last argument: you can use this index to extract the icon by using ExtractIconEx or whatelse you want. Here's a routine tha encapsulates this functionality:

' Display an icon browser and return the index of the selected icon,
' or -1 if the user didn't select any icon

Private Function DoIconDialog (ByVal sFile as String, Byval nIndex as Long) As _

    If SHChangeIconDialog(Me.hWnd, StrConv(sFile, vbUnicode), 0, nIndex) Then
        DoIconDialog = nIndex
        DoIconDialog = -1
    End If
End Function
Marco Bellinaso
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date