Sign in to follow this  
Followers 0

Using a png in my program

82 posts in this topic

#1 ·  Posted

I really need to be able to put .pngs in my program and I've read the topics showing how to do this but it seems like a LONG DRAWN OUT process that will take a lot of code and a lot of time.

I was wondering if there is a simpler way to do this and if there is I'd appreciate it if someone told me because I'm wondering if there is a way to do this with no more than 4 or 5 lines of code.

Please help! :P

Share this post


Link to post
Share on other sites



#2 ·  Posted

I really need to be able to put .pngs in my program and I've read the topics showing how to do this but it seems like a LONG DRAWN OUT process that will take a lot of code and a lot of time.

I was wondering if there is a simpler way to do this and if there is I'd appreciate it if someone told me because I'm wondering if there is a way to do this with no more than 4 or 5 lines of code.

Please help! :P

Here you go...

Very simple, 1 command and you have a PNG bacgkround. :P

However, it's the coding of all the buttons that takes time.

#include <PNGbackgroundUDF.au3>
CreateTransparentGUI($Title)

In the SAME folder you need an image called :

"Background.png" and "Grey2.gif".

I've included the Grey image, you need to put the background image in the SAME folder as PNGUDF.au3 =)

PNGUDF.zip

Share this post


Link to post
Share on other sites

#3 ·  Posted

Wow this is great!!! Thanks! :P

Btw, what do you mean when you say the coding of all the buttons takes all the time.

And what if I want to create more than one png? Windows won't let me have 10 or so images called background.png

Share this post


Link to post
Share on other sites

#4 ·  Posted

I think I gave you a good answer in your previous thread with the same subject:

http://www.autoitscript.com/forum/index.ph...3624&hl=png

:P

And even though that code is more than 4-5 lines it definitely not a long drawn out process.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#5 ·  Posted

Wow this is great!!! Thanks! :P

Btw, what do you mean when you say the coding of all the buttons takes all the time.

And what if I want to create more than one png? Windows won't let me have 10 or so images called background.png

This was designed for a single PNG.

You would have to understand how the function worked to use more than one PNG=) Figure it out, otherwise just use normal windows for children or whatever=)

Share this post


Link to post
Share on other sites

#6 ·  Posted

Monceres,

whenever I would move the window containing the png a black shadow would expand around it up to about 20 pixels.

If that wouldnt have happened, i wouldnt have started this thread...

Share this post


Link to post
Share on other sites

#7 ·  Posted

Monceres,

whenever I would move the window containing the png a black shadow would expand around it up to about 20 pixels.

If that wouldnt have happened, i wouldnt have started this thread...

If you comment out the GUICtrlCreatePic() line then no black pixel should appear.

Of course then you won't have a control that can receive events and such but that could be fixed by some manually work.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Well I've been studying the code for a while and thought that maybe I could increment the background.png name

like: (..."\Background" & 1 & ".png").

And thats all I've come up with (which is pretty sad...).

Can I have a hint? :P

Edited by IWantIt

Share this post


Link to post
Share on other sites

#9 ·  Posted

No hint?

Share this post


Link to post
Share on other sites

#10 ·  Posted

bump

Share this post


Link to post
Share on other sites

#11 ·  Posted

Im still lost on this one. Can somebody offer a helpful hint?

:P

Share this post


Link to post
Share on other sites

#12 ·  Posted

For $i=1 to 15

(..."\Background" & $i & ".png")

Next

I think thats sort of what you asked for...


Trust me to make SkyNet with AutoIt...

Share this post


Link to post
Share on other sites

#13 ·  Posted

yes, but that is only part of the solution to this problem. i will need someway to tell it to display each of the fifteen different images whenever called upon. (dont even know if im saying this right...)

@PsaltyDS: whenever you get back, it'd be really helpful if you could help...

here's the updated code (not much updated)

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
Global Const $AC_SRC_ALPHA      = 1
Global $hImage, $gui1, $controlGui

Func CreateTransparentGUI($Title)

;if FileExists(@ScriptDir & '\grey.gif') = 0 then 


_GDIPlus_Startup()
For $i=1 to 15
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Background" & $i & ".png")
Next
$ImageHeight = _GDIPlus_ImageGetHeight($hImage)
$ImageWidth = _GDIPlus_ImageGetWidth($hImage)
$gui1 = GUICreate($Title, $ImageWidth, $ImageHeight, -1, -1, $WS_popup, $WS_EX_LAYERED)
SetBitMap($gui1, $hImage, 255)
GUISetState()

$controlGui = GUICreate("ControlGUI", $ImageWidth, $ImageHeight, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI1)
GUICtrlCreatePic(@ScriptDir & "\grey2.gif", 0, 0, $ImageWidth, $ImageHeight)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState()

GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")


EndFunc

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
  if ($hWnd = $gui1) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc



Func SetBitmap($hGUI, $hImage, $iOpacity)
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  $hScrDC  = _WinAPI_GetDC(0)
  $hMemDC  = _WinAPI_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  $hOld    = _WinAPI_SelectObject($hMemDC, $hBitmap)
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
  DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity    )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  _WinAPI_ReleaseDC   (0, $hScrDC)
  _WinAPI_SelectObject($hMemDC, $hOld)
  _WinAPI_DeleteObject($hBitmap)
  _WinAPI_DeleteDC    ($hMemDC)
EndFunc

Share this post


Link to post
Share on other sites

#14 ·  Posted

NextBG()

Global $bgcount=1
Func NextBG()
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Background" & $bgcount & ".png")
$bgcount+=1
if $bgcount>15 then $bgcount=1; reset
Endfunc

How about this?


Trust me to make SkyNet with AutoIt...

Share this post


Link to post
Share on other sites

#15 ·  Posted

Im a confused ass retard. But out of all my confusion I think your first example was fine. Its just even though we are incrementing the picture file name, we still have to find a way to load them all on command and right now its only loading $hImage.

Share this post


Link to post
Share on other sites

#16 ·  Posted

You could try updating the graphic by deleting it and creating a new one each time. I saw a graphic that updates that way here. It should be able to be adapted to show a different png each time.


Trust me to make SkyNet with AutoIt...

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

This was designed for a single PNG.

You would have to understand how the function worked to use more than one PNG=) Figure it out, otherwise just use normal windows for children or whatever=)

Schzlopp:

Hi, I've been trying to figure it out for a long time now, whats the way to use it for multiple pngs?

Edited by IWantIt

Share this post


Link to post
Share on other sites

#18 ·  Posted

Bump

Share this post


Link to post
Share on other sites

#19 ·  Posted

Bump

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Bump.

Edited by IWantIt

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