Jump to content

Using a png in my program


Recommended Posts

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

Link to comment
Share on other sites

  • Replies 81
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

Link to comment
Share on other sites

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=)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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
Link to comment
Share on other sites

  • 2 weeks later...

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