# Function Reference

# _GUICtrlStatusBar_SetIcon

Sets the icon for a part

#include <GuiStatusBar.au3>
_GUICtrlStatusBar_SetIcon ( $hWnd, $iPart [, $hIcon = -1 [, $sIconFile = ""]] )

## Parameters

$hWnd | Handle to the control
$iPart | 0-based part index. If the control is in simple mode, this field is ignored.
$hIcon | [optional] Handle to the icon. If this value is -1, the icon is removed.
$sIconFile | [optional] Icon filename to be used.

## Return Value

Success: | True Or Icon Handle if $sIconFile is selected (see remark).
Failure: | False.
@error: | 11 if the hIcon cannot be created for the $sIconFile. @extended contain the _WinAPI_GetLastError(). 12 the $sIconFile cannot be set.

## Remarks

In case of the creation of an icon with $sIconFile the icon must be destroyed when the control is not used anymore.
This is a fix as during the display of the status bar the handle must be valid.
The previous example 2 was just working once because the GuiState() was issued before the _GUICtrlStatusBar_SetIcon().
But the icon was disappearing after a minimise and restore of the gui.

## Related

_GUICtrlStatusBar_GetIcon

## Example

### Example 1 use with icon handle

    #include "Extras\HelpFileInternals.au3"

    #include <GUIConstantsEx.au3>
    #include <GuiStatusBar.au3>
    #include <WinAPIIcons.au3>

    Example()

    Func Example()
        ; Create GUI
        Local $hGUI = GUICreate("StatusBar Get/Set Icon (v" & @AutoItVersion & ")", 450, 320, 100, 100)
        Local $hStatus = _GUICtrlStatusBar_Create($hGUI)

        ; Create memo control
        _MemoCreate(2, 8, 444, 259)
        GUISetState(@SW_SHOW)

        ; Set parts
        Local $aParts[4] = [75, 150, 300, 400]
        _GUICtrlStatusBar_SetParts($hStatus, $aParts)
        _GUICtrlStatusBar_SetText($hStatus, "Part 1")
        _GUICtrlStatusBar_SetText($hStatus, "Part 2", 1)

        ; Set icons
        Local $ahIcons[2]
        $ahIcons[0] = _WinAPI_LoadShell32Icon(23)
        $ahIcons[1] = _WinAPI_LoadShell32Icon(40)
        _GUICtrlStatusBar_SetIcon($hStatus, 0, $ahIcons[0])
        _GUICtrlStatusBar_SetIcon($hStatus, 1, $ahIcons[1])

        ; Show icon handles
        _MemoWrite("Part 0 icon handle .: 0x" & Hex(_GUICtrlStatusBar_GetIcon($hStatus, 0)))
        _MemoWrite("IsPtr = " & IsPtr(_GUICtrlStatusBar_GetIcon($hStatus, 0)) & " IsHWnd = " & IsHWnd(_GUICtrlStatusBar_GetIcon($hStatus, 0)))
        _MemoWrite("Part 1 icon handle .: 0x" & Hex(_GUICtrlStatusBar_GetIcon($hStatus, 1)))

        _MemoMsgBoxStatus("", -1, $hGUI) ; no more action, wait GUI for closing

        ; Loop until the user exits.
        Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; Free icons
        _WinAPI_DestroyIcon($ahIcons[0])
        _WinAPI_DestroyIcon($ahIcons[1])

        GUIDelete()
    EndFunc   ;==>Example

### Example 2 direct use with icon file

    #include "Extras\HelpFileInternals.au3"

    #include <GUIConstantsEx.au3>
    #include <GuiStatusBar.au3>
    #include <WinAPIIcons.au3>

    Example()

    Func Example()
        ; Create GUI
        Local $hGUI = GUICreate("StatusBar Get/Set Icon (v" & @AutoItVersion & ")", 450, 320)
        Local $hStatus = _GUICtrlStatusBar_Create($hGUI)

        ; Create memo control
        _MemoCreate(2, 8, 444, 259)

        ; Set parts
        Local $aParts[3] = [75, 150, 300] ;, 400]
        _GUICtrlStatusBar_SetParts($hStatus, $aParts)
        _GUICtrlStatusBar_SetText($hStatus, "Part 0")
        _GUICtrlStatusBar_SetText($hStatus, "Part 1", 1)

        ; Set icons
        Local $hIcon1 = _GUICtrlStatusBar_SetIcon($hStatus, 0, 23, "shell32.dll")
        Local $hIcon2 = _GUICtrlStatusBar_SetIcon($hStatus, 1, 23, "shell32.dll")

        GUISetState(@SW_SHOW)

        ; Show icon handles
        _MemoWrite("Part 0 icon handle .: 0x" & Hex(_GUICtrlStatusBar_GetIcon($hStatus, 0)))
        _MemoWrite("Part 1 icon handle .: 0x" & Hex(_GUICtrlStatusBar_GetIcon($hStatus, 1)))

        _MemoMsgBoxStatus("", -1, $hGUI) ; no more action, wait GUI for closing

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; Free icons
        _WinAPI_DestroyIcon($hIcon1)
        _WinAPI_DestroyIcon($hIcon2)

        GUIDelete()
    EndFunc   ;==>Example