Jump to content
Sign in to follow this  
taotao878

Show png on the GUI

Recommended Posts

taotao878

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

Opt("MustDeclareVars", 1)

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

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

; Load PNG image
_GDIPlus_StartUp()
$hImage   = _GDIPlus_ImageLoadFromFile("MAIN.png")

; Draw PNG image
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 50, 50)

GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")

; Loop until user exits
do
until GUIGetMsg() = $GUI_EVENT_CLOSE

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


Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 50, 50)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
EndFunc

Edited by taotao878

Share this post


Link to post
Share on other sites
Zedna

Little optimized version:

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

Opt("MustDeclareVars", 1)

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

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

; Load PNG image
_GDIPlus_StartUp()
$hImage   = _GDIPlus_ImageLoadFromFile("MAIN.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)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 50, 50)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
EndFunc
Edited by Zedna

Share this post


Link to post
Share on other sites
taotao878

#include <GuiConstantsEX.au3>
#include <GDIPlus.au3>

Global $hGui, $iExt
Global $hPic, $hImage, $hGraphic


$hGui = GUICreate("show png", 350, 300)
$Button = GUICtrlCreateButton ("view", 270, 270, 75, 21)
GUISetState()


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button
            $OpenFile = FileOpenDialog("Select png file", "", "png(*.png)")
            _GDIPlus_StartUp()
            $hImage   = _GDIPlus_ImageLoadFromFile($OpenFile)
            $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
            _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
            GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
    EndSwitch   
WEnd
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()



Func MY_WM_PAINT($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

It have problem to show png with GDI+, likes attachment

post-24544-1209517765_thumb.jpg

Share this post


Link to post
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
Sign in to follow this  

×