Jump to content

Multiple PNG Images on GUI


dantay9
 Share

Recommended Posts

I was surfing through the forums looking for something that I had previously missed and came across JRowe's topic on creating a gui out of multiple png images. I saw the complexity of using several guis so I thought I would post what I have used for quite a while to make this process much easier.

This is a fairly simple udf for newcomers (or anyone new to GDI+) that allows you to add images and strings to an array and they will be automatically be drawn on top of the background when SetBitmapEx is called. There is only one gui so you won't have to juggle several windows just to get a good looking gui.

This example was meant to be edited based on personal preference. I refrained from adding too much complexity to the code without sacrificing a whole lot of functionality. Everyone is free to change this udf to suite your project.

The files can be downloaded here.

Updated 3/11/10: Fixed a few bugs; added gui centering; added examples

Updated 3/3/10: Added ability to draw strings

Edited by dantay9
Link to comment
Share on other sites

  • 2 weeks later...

Any chance you could give an example with more than one image? I've tried a couple times to tweak. Also is $Style defined in a udf, maybe I'm using an old autoit build.

Is this how you would do it?

Dim $Images[1][9] = [["Dice.png", 0, 100, 50, 50, 0, 0, 100, 50]]

_GDIPlus_Startup()

$GUI = GUICreate("", 300, 300, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
AddImage($Images, "Dice.png", 50, 100, 50, 50, 0, 100)
AddImage($Images, "Picture1.png", 150, 100, 150, 50, 200, 100)
;AddString($Images, "STRING", 25, 25, "Arial", 20, 1, 0xFFFF0000)
SetBitmapEx($GUI, "Dice.png", 255, $Images, -1, -1)
SetBitmapEx($GUI, "Picture1.png", 255, $Images, -1, -1)
GUISetState()
Link to comment
Share on other sites

Oops. $Style was the old name of my variable but I changed it to $Attribute. Fixed it now.

SetBitmap should only be called once. There is going to be a single background and then the images in the array will be painted on top of the background.

Maybe the small example that I gave was a bit too small. I will work on adding more examples. Anyways, here is another example that shows a bit of a different look to the code. This is also in the new download.

#Region Create Images Array
Dim $Images[1][9] ;doesn't have to be initialized, but can be
AddImage($Images, "Image 1.png", 50, 50, 50, 50, 0, 50)
AddImage($Images, "Image 2.png", 50, 50, 50, 50, 50, 150)
AddString($Images, "STRING", 15, 115, "Arial", 20, 1, 0xFFFF0000)
#EndRegion Create Images Array

_GDIPlus_Startup()

$GUI = GUICreate("", 300, 300, -1, -1, $WS_POPUP, $WS_EX_LAYERED) ;don't forget, the window must be layered
SetBitmapEx($GUI, "Dice.png", 255, $Images, -1, -1) ;set the background that will be drawn on top of
GUISetState()

;Loop until ESC is pressed
Do
    Sleep(100)
Until _IsPressed("1B")

_GDIPlus_Shutdown()

Edit: Added a few more examples. The examples are a little more diverse now.

Edited by dantay9
Link to comment
Share on other sites

  • 1 year later...
  • 4 months later...

Unfortunately it appears that the OP hasn't been on the site since June of last year, unless another user has the code I wouldn't hold my breath too long waiting.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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