Sign in to follow this  
Followers 0
Dolemite50

PngKong

19 posts in this topic

Hi,

I stumbled across this post regarding Png-based Guis and thought I'd try contributing to a worthy cause.

Last year I developed a script based on Volly and ProgAndy's work that determines it's own layout and functionality based on the graphics you provide. I haven't had a chance to check out newer renditions of Png Guis, but I abandoned this project long ago due to a snag I couldn't resolve. The problem is that I never found a way to destroy or delete an image once created. I suspect that my mouse-overs may have been recreating images rather than replacing them and for all I know buttons were 100 images deep. Anybody else run into that?

JRowe, your script is looking great. Feel free to pillage my code if you find anything of use. If anybody gets Png-Guis dialed in please drop me a line. Exporting straight from FireWorks to a GUI layout is a luxury.

/////////////////////////////////

This scrawny 24-line snippet demonstrates a GUI with multi-state buttons, toggle buttons, buttons assigned to a group, buttons disabled as a group, swappable decor images, and an alternating background.

#include <PngKong.au3>
PK_GUI("PngKong - Basic Demo")
Func PK_AddItems()
    PK_AddItem("btnExit", 241, 29)
    PK_AddItem("btnShockIt/btnReset", 31, 260, "MyGroup", 0)
    PK_AddItem("btnChangeGui", 161, 260, "MyGroup")
    PK_AddItem("btnDisableMyGroup/btnEnableMyGroup", 101, 322, 0)
    PK_AddItem("picAuto/picAutoShock", 50, 52)
EndFunc
Func _DisableMyGroup()
    PK_SetGroupState("MyGroup", 4)
EndFunc
Func _EnableMyGroup()
    PK_SetGroupState("MyGroup", 1)
EndFunc
Func _ChangeGui()
    PK_SwapBgPic()
EndFunc
Func _ShockIt()
    PK_SwapPic("picAuto")
EndFunc
Func _Exit()
    Exit
EndFunc

Posted Image

Posted Image

Source

Enjoy!

Share this post


Link to post
Share on other sites



PngKong leaks. I would say PK_DrawItem() issue after a quick look.

Visually very cool.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

it have a erorr:

Calling: _Exit

Deleting ControlGui: 0x000F069A

Deleting BgGui: 0x00080580

Disposing of bg graphic: 34323592

I:\17.9.09\PngKong\PngKong.au3 (640) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

ConsoleWrite("Destroying image: " & $PK_Items[$i][12] & " in item: " & $PK_Items[$i][3] & @CRLF)

ConsoleWrite("Destroying image: " & ^ ERROR

:) :)

Share this post


Link to post
Share on other sites
:) Very nice.

Share this post


Link to post
Share on other sites

Hi guys, thanks for the feedback.

@trancexx - How were you able to verify the leak? Do you happen to know of a way to get a readout of all images the script has created? If I can just get past that issue it'd be usable again.

@AdmiralAlkex - Thanks for noticing the old tidy error. It's not valid, I wonder why Tidy didn't remove it?

@toxicvn - It looks like your images may not have been created properly to begin with because it was missing a required cleanup on the way out. Did it work at all?

@P5ych0Gigabyte - Now that's interesting. On my old XP box they lined up perfectly but when I ran it again for the first time on Win 7 32 the images were off. Not only that but they were off in the same direction as yours, which means prior to the adjustment the "x" on your 64 wouldn't have even been in the ballpark. Not good. That's just the kind of thing that keeps me from commiting to the PNG approach. Granted I'm not an expert on the subject but the behavior might lean towards something hairy like cross-platform rendering issues. Hopefully one of the Png gurus can direct me to a flaw. Thanks, that was very useful feedback.

Thanks Authenticity. :)

Good lord P5ych0Gigabyte, quit playing with that thing before it fries your board! :)

Thanks again all, excellent feedback.

Share this post


Link to post
Share on other sites

@toxicvn - It looks like your images may not have been created properly to begin with because it was missing a required cleanup on the way out. Did it work at all?

:) :)

it work fine but when i click X button to close it then it show erorr:

Calling: _Exit

Deleting ControlGui: 0x000F069A

Deleting BgGui: 0x00080580

Disposing of bg graphic: 34323592

I:\17.9.09\PngKong\PngKong.au3 (640) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

ConsoleWrite("Destroying image: " & $PK_Items[$i][12] & " in item: " & $PK_Items[$i][3] & @CRLF)

ConsoleWrite("Destroying image: " & ^ ERROR

:P:idea:

Share this post


Link to post
Share on other sites

In line 640

ConsoleWrite("Destroying image: " & $PK_Items[$i][11] & " in item: " & $PK_Items[$i][3] & @CRLF)

Change $PK_Items[$i][12] to $PK_Items[$i][11]. That needs to be made dynamic, probably, but I haven't looked at the whole setup yet.

Awesome work, dolemite50!

The pink fringe is, I'm assuming, and artifact of whatever image editor you're using? I redid some of the images and its gone, so I'll upload those after the memory leak is addressed. Again, awesome work man!

Share this post


Link to post
Share on other sites

Looks to me like the _GDIPlus_ImageLoadFromFile() calls are whats causing the leaks. They're called repeatedly, reloading the images without ever disposing of them, increasing the used memory every time an image changes.

Affected functions are PK_DrawItem(), PK_GUI(), PK_AddItem(), PK_SwapBgPic(), and PK_ShowPic().

If anyone knows what to replace _GDIPlus_ImageLoadFromFile() with offhand, I'd be grateful. Maybe an array of images loaded once in an initialization, then accessed byref?

Share this post


Link to post
Share on other sites

Change the exit button line in the demo to

PK_AddItem("btnExit", 241, 33)

On some systems, it appears the menu bar is sized differently, which is what could cause the problem.

Share this post


Link to post
Share on other sites

:) :whistle:thank

thank

:) :whistle:thank

Share this post


Link to post
Share on other sites

Alllllriiight,.. JRowe in the house! Thanks for diving in man, you really hit the ground running.

My problem is that I have no idea how to manipulate an array of images created with _GDIPlus_ImageLoadFromFile. Even a toggle of their visibility would work but the GDI stuff is lost on me. When I posted for help (referenced in first post) and Smoke N didn't have an answer I knew that I was in wayyyy over my head.

Well thanks again and let me know if you have any questions regarding my code. Sorry if it's a little sloppy but I only had time to blow the dust off and upload. I should be pretty freed up towards the middle of the week, let me know if you want some help on anything. I have a few more PNG experiments you might be interested in.

Thanks again. :)

Share this post


Link to post
Share on other sites

It's really simple, actually. Think of GDIPlus as a container for your graphics. You can put graphics in in the form of images or drawings. You can then specify where you'd like those graphics to be put, whether it's a window or another device context entirely. What you're doing with the _GDIPlusLoadImageFromFile is loading the image file into the GDIPlus container. Every time you do that, it takes up another chunk of memory, as big as the image file. Meaning if a function calls _GDIPlusLoadImageFromFil() 50 times on an image, it's going to take that image and load it into memory 50 times. So what you do, is load it into memory once, assigning the handle to an array, and then do operations with that handle, never calling GDIPlusLoadImageFromFile() again. This is, btw, the reason I haven't released anything on a PNG gui system. It's a pain in the ass and I've got mashed up experiments all over the place.

I'm looking for an interim fix, to simply release and clean the used memory. Very, very cool :)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

thank very cool but how is add

Func PK_AddItems()

PK_AddItem("btnExit", 241, 33)

PK_AddItem("btnShockIt/btnReset", 31, 260, "MyGroup", 0)

PK_AddItem("btnChangeGui", 161, 260, "MyGroup")

PK_AddItem("btnDisableMyGroup/btnEnableMyGroup", 101, 322, 0)

PK_AddItem("picAuto/picAutoShock", 50, 52)

$Input1 = GUICtrlCreateInput("Input1", 328, 152, 201, 21);add GUICtrlCreateInput

$Input2 = GUICtrlCreateInput("Input2", 328, 152, 201, 21);add GUICtrlCreateInput

GUISetState(@SW_SHOW)

EndFunc

this add code ,dont worked,

Edited by mesale0077

Share this post


Link to post
Share on other sites

Hmmm,

I found this code by Yashied, is this what we're looking for?

Func _SetImageHover($ControlID, $sImage)

    Local $hWnd = GUICtrlGetHandle($ControlID)
    Local $hImage, $hBitmap

;    _GDIPlus_Startup()
    $hImage = _GDIPlus_BitmapCreateFromFile($sImage)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageDispose($hImage)
;    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject(_SendMessage($hWnd, 0x0173))
    _SendMessage($hWnd, 0x0172, 0, $hBitmap)
    $hImage = _SendMessage($hWnd, 0x0173)
    If $hImage <> $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf
EndFunc   ;==>_SetImageHover

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

I was toying with Yashied's _SetImage func (Icons.au3) and this seems to work fine:

#Include <Icons.au3>

$hForm = GUICreate('MyGUI', 178, 192)
GUICtrlCreatePic('hg.JPG', 0, 0, 178, 192)
$Pic = GUICtrlCreatePic('', 65, 60, 48, 48)
_SetImage($Pic, 'test.png')
GUISetState()
Sleep(2000)
_SetImage($Pic, 'test2.png')
Sleep(2000)
Do
Until GUIGetMsg() = -3

Can it really be that simple? Not to say that Yashied's Icons script is simple, of course. I just wasn't expecting to find such a silver platter solution in less code than it takes to declare a variable.

Well thanks, Yashied! I dub thee Png King. :)

Edited by Dolemite50

Share this post


Link to post
Share on other sites

I hate to bring up such old topics but does anybody have the source for this still? I could really benifit from looking at it.

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  
Followers 0