Function Reference


GUICtrlCreatePic

Creates a Picture control for the GUI.

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

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
exStyle [optional] Defines the extended style of the control. See Extended Style Table.

Return Value

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

Remarks

To set or change information in the control see GUICtrlUpdate....

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

If you want to have a picture having the same size as the file content just use width=height=0.

To have a transparent picture it is needed to create the GUI window with WS_EX_LAYERED extended style. The left-top pixel will be used as the transparency color. If several pictures are created the last picture is defining 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, as the other controls will overlap, it's important to disable the pic control and create it after the others controls: GuiCtrlSetState(-1,$GUI_DISABLE). This is not enough for Tab or Listview control which behave differently. In this case you need to create the picture with the $WS_CLIPSIBLINGS style, GuiCtrlSetState(-1,$GUI_ONTOP) is necessary for the Tab, TreeView or Listview control.

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

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

PNG can be used with GDI+. See example 3.

Related

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

Example


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

Global $gui, $guiPos, $pic, $picPos

Example1()
Example2()

;----- example 1 ----
Func Example1()
    Local $n, $msg

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

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

    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd


    ; resize the control
    $n = GUICtrlSetPos($n, 50, 50, 200, 100)
    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd

    GUIDelete()
EndFunc   ;==>Example1

;----- example 2
Func Example2()
    Local $msg

    $gui = GUICreate("test transparentpic", 200, 100)
    $pic = GUICreate("", 68, 71, 10, 20, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gui)
    GUICtrlCreatePic("..\GUI\merlin.gif", 0, 0, 0, 0)

    GUISetState(@SW_SHOW, $pic)
    GUISetState(@SW_SHOW, $gui)

    HotKeySet("{ESC}", "main")
    HotKeySet("{LEFT}", "left")
    HotKeySet("{RIGHT}", "right")
    HotKeySet("{DOWN}", "down")
    HotKeySet("{UP}", "up")
    $picPos = WinGetPos($pic)
    $guiPos = WinGetPos($gui)

    Do
        $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE

    HotKeySet("{ESC}")
    HotKeySet("{LEFT}")
    HotKeySet("{RIGHT}")
    HotKeySet("{DOWN}")
    HotKeySet("{UP}")
EndFunc   ;==>Example2

Func main()
    $guiPos = WinGetPos($gui)
    WinMove($gui, "", $guiPos[0] + 10, $guiPos[1] + 10)
EndFunc   ;==>main

Func left()
    $picPos = WinGetPos($pic)
    WinMove($pic, "", $picPos[0] - 10, $picPos[1])
EndFunc   ;==>left

Func right()
    $picPos = WinGetPos($pic)
    WinMove($pic, "", $picPos[0] + 10, $picPos[1])
EndFunc   ;==>right

Func down()
    $picPos = WinGetPos($pic)
    WinMove($pic, "", $picPos[0], $picPos[1] + 10)
EndFunc   ;==>down

Func up()
    $picPos = WinGetPos($pic)
    WinMove($pic, "", $picPos[0], $picPos[1] - 10)
EndFunc   ;==>up

;----- example 3 PNG work araund by Zedna
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

Global $hGUI, $hImage, $hGraphic, $hImage1

; Create GUI
$hGUI = GUICreate("Show PNG", 250, 250)

; Load PNG image
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile("..\GUI\Torus.png")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState()

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

; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

; Draw PNG image
Func MY_WM_PAINT($hWnd, $msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_PAINT