Jump to content

Add png image in a GUI window


Recommended Posts

Hello. Sorry me, but i need an example...

Necessary to add a simple .png image in a GUI window with the use of GDI+.

Images:

Posted Image

Posted Image

Result:

Posted Image

Thanks!

Hope that help you.

#include <GDIPlus.au3>

_GDIPlus_Startup()
Global $Image1 = _GDIPlus_ImageLoadFromFile("png1.png")
Global $Image2 = _GDIPlus_ImageLoadFromFile("png2.png")

$GUI = GUICreate("Example",200,200)
GUISetState()

Global $Graphic = _GDIPlus_GraphicsCreateFromHWND($GUI)
_GDIPlus_GraphicsDrawImageRect($Graphic, $Image1,25,25,100,100)
_GDIPlus_GraphicsDrawImageRect($Graphic, $Image2,75,75,100,100)

While 1
    $MSG = GUIGetMsg()
    Switch $MSG
        Case -3
            Quit()
    EndSwitch
WEnd

Func Quit()
    _GDIPlus_ImageDispose($Image1)
    _GDIPlus_ImageDispose($Image2)
    _GDIPlus_GraphicsDispose($Graphic)
    _GDIPlus_Shutdown()
    Exit
EndFunc

When the words fail... music speaks.

Link to comment
Share on other sites

Here is modified version using WM_PAINT to avoid lost image after hidding by another application

#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

_GDIPlus_Startup()
Global $Image1 = _GDIPlus_ImageLoadFromFile("png1.png")
Global $Image2 = _GDIPlus_ImageLoadFromFile("png2.png")

$GUI = GUICreate("Example",200,200)
Global $Graphic = _GDIPlus_GraphicsCreateFromHWND($GUI)
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState()

While 1
    $MSG = GUIGetMsg()
    Switch $MSG
        Case -3
            Quit()
    EndSwitch
WEnd

Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
 _WinAPI_RedrawWindow($GUI, 0, 0, $RDW_UPDATENOW) ; force redraw of GUI (Rect=0 Region=0)
 ; then draw my stuff on top
 _GDIPlus_GraphicsDrawImageRect($Graphic, $Image1,25,25,100,100)
 _GDIPlus_GraphicsDrawImageRect($Graphic, $Image2,75,75,100,100)
 _WinAPI_RedrawWindow($GUI, 0, 0, $RDW_VALIDATE) ; then force no-redraw of GUI
 Return $GUI_RUNDEFMSG
EndFunc

Func Quit()
    _GDIPlus_ImageDispose($Image1)
    _GDIPlus_ImageDispose($Image2)
    _GDIPlus_GraphicsDispose($Graphic)
    _GDIPlus_Shutdown()
    Exit
EndFunc
Link to comment
Share on other sites

#Include <Icons.au3>

Global Const $sPng = RegRead('HKLM\SOFTWARE\AutoIt v3\AutoIt', 'InstallDir') & '\Examples\GUI\Advanced\Images\Torus.png'

$Form = GUICreate('Test', 253, 244)

$Pic1 = GUICtrlCreatePic('', 10, 10, 193, 184)
$Pic2 = GUICtrlCreatePic('', 60, 60, 193, 184)

GUISetState()

_SetImage($Pic2, $sPng)
_SetImage($Pic1, $sPng)

Do
Until GUIGetMsg() = -3

Icons.au3

:D

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...