Jump to content

PNG - remove from Gui


Tankbuster
 Share

Go to solution Solved by UEZ,

Recommended Posts

Task: Display a PNG, and remove it on command.

I searched and read the help file for some time. I came up with a solution but that was not nice (was something like fill the previous image with the backgroundcolor...)

So I re-used the example of the PNG display (with a little mod) and ask kindly if someone could give me a hint on the _remove() function.

I think there is a easier method or isn't there one?

I attached the images but I think it does not matter just use any png files._png.zip

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

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

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

; Load PNG image
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile("big.png")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$button1=GUICtrlCreateButton("change",400,20,100,20)
$button2=GUICtrlCreateButton("remove",400,50,100,20)
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState(@SW_SHOW)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        case $button1
            _change()
        case $button2
            _remove()
    EndSwitch
WEnd



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

func _remove()
    ;~ mmmh
EndFunc

func _change()
    $hImage = _GDIPlus_ImageLoadFromFile("small.png")
    _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImage, 0, 0,300,300,0,0,300,300)
EndFunc

; Draw PNG image
Func MY_WM_PAINT($hWnd, $msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImage, 0, 0,300,300,0,0,300,300)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_PAINT
Link to comment
Share on other sites

  • Solution

What do you mean with remove? You mean clear the image? If yes then try this:

func _remove()
    _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)
EndFunc

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

thx for your answer. As I read a lot of posting from you (UEZ) about GDIPlus here, I think it is the best I could do.

(in other words if you came up with a similar idea like me, there is nothing better - see my first post).

I thought maybe there is something, that is better than "clear". (like destroy object, recreate or what ever)

Sounds not very thankful, didn't it?

But I am thankful.

I honor your response as "solved". thx.

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...