GetIcon

 

Description

Retrieves an icon from the specified executable file, dynamic-link library (DLL), or icon file.

The icon (image) can be assigned to the Picture, DisabledPicture or DownPicture property of other controls (like commandbuttons) or can be added to an ImageList control.

Syntax

[Set oPic =] oDlg.GetIcon ( File, SmallICon, IconIndex, BackColor )

Parameters

Part

Description

Set oPic =

An object variable or picture property you want to assign the icon to.

oDlg

A reference to the WshDialog.Kit automation object (as returned by the Wscript or VBScript CreateObject methods)

File

String expression specifying the name of an executable file, DLL, or icon file from which the icon will be extracted. Can include folder and drive.

SmallIcon

(optional) Boolean indicating whether to retrieve a large or small icon.
The default is False.

IconIndex

(optional, ) The zero-based index of the icon to extract. The default is 0.

BackColor

(optional) The background color to be used when drawing the icon. Normally you would specify the background color of the control on which you want the icon to be drawn. The default is &H8000000F (which is the standard Windows Button Face color).

Example

Option Explicit

Const vbModal = 1

Dim oShell, oDlg, oFrm, oCtl, sWindir, X, sX

'Create the Shell object to access the Windir environment variable
Set oShell = Wscript.CreateObject("WScript.Shell")
sWindir = oShell.ExpandEnvironmentStrings("%WinDir%")

'Create the WshDialog.Kit object and store a reference in oDlg
Set oDlg = Wscript.CreateObject("WshDialog.Kit", "oDlg_")

'Add a new form and store a reference to it in the variable oFrm
Set oFrm = oDlg.NewForm("Sample")

'Set the form's caption
oFrm.Caption = "Testing the GetIcon method"

'Add a button NOTEPAD to the form and retrieve the (large) icon from Notepad.exe
Set oCtl = oFrm.NewButton("NOTEPAD", 150, 150, 1000, 1000, "&Notepad")
oCtl.Picture =
oDlg.GetIcon(sWindir & "\Notepad.exe")

'Add some buttons to the form and retrieve the small and large icons from Explorer.exe
For X = 0 To 6
    sX = Trim(CStr(X))
    
'Add a small button, retrieve small icon X from Explorer.exe and add a tooltip
    Set oCtl = oFrm.NewButton("SMALL" & sX, 150 + X * 500, 1500, 400, 400, "")
    oCtl.Picture =
oDlg.GetIcon(sWindir & "\Explorer.exe", True, X)
    oCtl.TooltipText = "Small Explorer Icon " & sX
    
'Add a large button, retrieve large icon X from Explorer.exe and add a tooltip
    Set oCtl = oFrm.NewButton("LARGE" & sX, 150 + X * 750, 2250, 750, 750, "")
    oCtl.Picture =
oDlg.GetIcon(sWindir & "\Explorer.exe",, X)
    oCtl.TooltipText = "Large Explorer Icon " & sX
Next

'Automatically size the form and show it (modally)
oFrm.Autosize
oFrm.Show vbModal

'Show which button was selected to dismiss the form
MsgBox "The " & oDlg.Clicked & " button was selected"