Function Reference


GUICtrlCreatePic

Creates a Picture control for the GUI.

GUICtrlCreatePic ( filename, left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )

Parameters

filename filename of the picture to be loaded : supported types BMP, JPG, GIF(but not animated).
left The left side of the control. If -1 is used then left will be computed according to GUICoordMode.
top The top of the control. If -1 is used then top will be computed according to GUICoordMode.
width [optional] The width of the control (default is the previously used width).
height [optional] The height of the control (default is the previously used height).
style [optional] Defines the style of the control. See GUI Control Styles Appendix.
    default (-1) : $SS_NOTIFY
    forced style : $SS_BITMAP | $SS_CENTERIMAGE
exStyle [optional] Defines the extended style of the control. See Extended Style Table.

Return Value

Success: the identifier (controlID) of the new control.
Failure: 0 if picture cannot be created.

Remarks

To set or change information in the control see GUICtrlUpdate...() functions.

To update the picture after the dialog box is displayed just use GUICtrlSetImage().

To set the picture control to the same size as the file content set width and height to 0.

To have a transparent picture create the GUI with the WS_EX_LAYERED extended style. The left-top pixel will be used as the transparency color. If several pictures are created the last picture defines the transparent color. See example 2.

To combine styles with the default style use BitOR($GUI_SS_DEFAULT_PIC, newstyle, ... ).
To use the values specified above you must #include <StaticConstants.au3> in your script.

Default resizing is $GUI_DOCKSIZE.

If a picture is set as a background picture the other controls will overlap, so it is important to disable the pic control: GUICtrlSetState(-1, $GUI_DISABLE).

The extended style $GUI_WS_EX_PARENTDRAG can be used to allow the dragging of the parent window for windows that do not have a titlebar (no $WS_CAPTION style in GUICreate()).

The background is always set to transparent. GUICtrlSetBkColor() has no effect on pic control.

Related

GUICoordMode (Option), GUICtrlSetImage, GUICtrlUpdate..., GUIGetMsg

Example

Example 1

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
        GUICreate("My GUI picture", 350, 300, -1, -1, $WS_SIZEBOX + $WS_SYSMENU) ; will create a dialog box that when displayed is centered

        GUISetBkColor(0xE0FFFF)
        Local $idPic = GUICtrlCreatePic("..\GUI\mslogo.jpg", 50, 50, 200, 50)

        GUISetState(@SW_SHOW)

        ; Loop until the user exits.
        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop

                EndSwitch
        WEnd

        ; resize the control
        GUICtrlSetPos($idPic, 50, 50, 200, 100)

        Local $idMsg
        ; Loop until the user exits.
        While 1
                $idMsg = GUIGetMsg()

                If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
        WEnd

        GUIDelete()
EndFunc   ;==>Example

Example 2

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $g_hGui, $g_aGuiPos, $g_hPic, $g_aPicPos

Example()

Func Example()
        $g_hGui = GUICreate("test transparentpic", 200, 100)
        $g_hPic = GUICreate("", 68, 71, 10, 20, $WS_POPUp, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $g_hGui)
        GUICtrlCreatePic("..\GUI\merlin.gif", 0, 0, 0, 0)

        GUISetState(@SW_SHOW, $g_hPic)
        GUISetState(@SW_SHOW, $g_hGui)

        HotKeySet("{ESC}", "Main")
        HotKeySet("{Left}", "Left")
        HotKeySet("{Right}", "Right")
        HotKeySet("{Down}", "Down")
        HotKeySet("{Up}", "Up")
        $g_aPicPos = WinGetPos($g_hPic)
        $g_aGuiPos = WinGetPos($g_hGui)

        ; Loop until the user exits.
        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop

                EndSwitch
        WEnd

        HotKeySet("{ESC}")
        HotKeySet("{Left}")
        HotKeySet("{Right}")
        HotKeySet("{Down}")
        HotKeySet("{Up}")
EndFunc   ;==>Example

Func Main()
        $g_aGuiPos = WinGetPos($g_hGui)
        WinMove($g_hGui, "", $g_aGuiPos[0] + 10, $g_aGuiPos[1] + 10)
EndFunc   ;==>Main

Func Left()
        $g_aPicPos = WinGetPos($g_hPic)
        WinMove($g_hPic, "", $g_aPicPos[0] - 10, $g_aPicPos[1])
EndFunc   ;==>Left

Func Right()
        $g_aPicPos = WinGetPos($g_hPic)
        WinMove($g_hPic, "", $g_aPicPos[0] + 10, $g_aPicPos[1])
EndFunc   ;==>Right

Func Down()
        $g_aPicPos = WinGetPos($g_hPic)
        WinMove($g_hPic, "", $g_aPicPos[0], $g_aPicPos[1] + 10)
EndFunc   ;==>Down

Func Up()
        $g_aPicPos = WinGetPos($g_hPic)
        WinMove($g_hPic, "", $g_aPicPos[0], $g_aPicPos[1] - 10)
EndFunc   ;==>Up