Sign in to follow this  
Followers 0
Unc3nZureD

Transparent PNG + GUI Elements

6 posts in this topic

Today I found this cool script:

#include 
#include 
#include 
Dim $_GuiDelete

$_PngPath = @ScriptDir & "\bg.png"
_GDIPlus_Startup ( )
$_Image = _GDIPlus_ImageLoadFromFile ($_PngPath)
$_Width = _GDIPlus_ImageGetWidth ($_Image)
$_Height = _GDIPlus_ImageGetHeight ( $_Image )
$_Ratio = $_Width / $_Height
$_Width = 600
$_Gui = GUICreate ( "gui", $_Width , $_Width / $_Ratio, -1, -1, -1, BitOR ( $WS_EX_LAYERED, $WS_EX_TOPMOST ) )
$_Image = _ImageResize ( $_PngPath, $_Width, $_Width / $_Ratio )
_SetBitMap ( $_Gui, $_Image, 255, $_Width, $_Width / $_Ratio )
$Progress1 = GUICtrlCreateProgress(8, 8, 150, 17)
GUISetState (@SW_SHOW)

While 1
Sleep(20)
WEnd

_GDIPlus_GraphicsDispose ($_Image)
_GDIPlus_Shutdown()
Exit

Func _SetBitmap ( $hGUI, $hImage, $iOpacity, $n_width, $n_height )
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", $n_width )
DllStructSetData ( $tSize, "Y", $n_height )
$tSource = DllStructCreate ( $tagPOINT )
$pSource = DllStructGetPtr ( $tSource )
$tBlend = DllStructCreate ( $tagBLENDFUNCTION )
$pBlend = DllStructGetPtr ( $tBlend )
DllStructSetData ( $tBlend, "Alpha", $iOpacity )
DllStructSetData ( $tBlend, "Format", 1 )
_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 ;==> _SetBitmap ( )

Func _ImageResize ( $sInImage, $newW, $newH, $sOutImage = "" )
Local $oldImage, $GC, $newBmp, $newGC
If $sOutImage = "" Then _GDIPlus_Startup ( )
$oldImage = _GDIPlus_ImageLoadFromFile ( $sInImage )
$GC = _GDIPlus_ImageGetGraphicsContext ( $oldImage )
$newBmp = _GDIPlus_BitmapCreateFromGraphics ( $newW, $newH, $GC )
$newGC = _GDIPlus_ImageGetGraphicsContext ( $newBmp )
_GDIPlus_GraphicsDrawImageRect ( $newGC, $oldImage, 0, 0, $newW, $newH )
_GDIPlus_GraphicsDispose ( $GC )
_GDIPlus_GraphicsDispose ( $newGC )
_GDIPlus_ImageDispose ( $oldImage )
If $sOutImage = "" Then
Return $newBmp
Else
_GDIPlus_ImageSaveToFile ( $newBmp, $sOutImage )
_GDIPlus_BitmapDispose ( $newBmp )
_GDIPlus_Shutdown ( )
Return 1
EndIf
EndFunc ;==> _ImageResize ( )

It works well, but I've got a problem with it. If you see it upper, there's a "$Progress1 = GUICtrlCreateProgress(8, 8, 150, 17)" line. It doesn't want to show up :S Any idea how to fix?

Share this post


Link to post
Share on other sites



Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Deleting what?

I mean I want it TO SHOW UP, but it doesn't want (doesn't work).

Edited by Unc3nZureD

Share this post


Link to post
Share on other sites

why don't you draw one with gdi+ commands?


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

Maybe any easier idea? :D I don't really know how to do it, and later I have to animate it... Isn't there any better solution to make a GUI with the background of a transparent picture, and I would like to add two progressbar later. :S Idea which UDF I should use?

Share this post


Link to post
Share on other sites

As already mentioned here: use a child gui.

#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Dim $_GuiDelete

$_PngPath = @ScriptDir & "bg.png"
_GDIPlus_Startup ( )
$_Image = _GDIPlus_ImageLoadFromFile ($_PngPath)
$_Width = _GDIPlus_ImageGetWidth ($_Image)
$_Height = _GDIPlus_ImageGetHeight ( $_Image )
$_Ratio = $_Width / $_Height
$_Width = 600
$_Gui = GUICreate ( "gui", $_Width , $_Width / $_Ratio, -1, -1, -1, BitOR ( $WS_EX_LAYERED, $WS_EX_TOPMOST ) )
$_Image = _ImageResize ( $_PngPath, $_Width, $_Width / $_Ratio )
_SetBitMap ( $_Gui, $_Image, 255, $_Width, $_Width / $_Ratio )
$hGUI_Child = GUICreate("", 150, 17, 8, 8, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_MDICHILD, $_Gui)
$Progress1 = GUICtrlCreateProgress(0, 0, 150, 17,  $PBS_SMOOTH)
GUISetState (@SW_SHOW, $_Gui)
GUISetState (@SW_SHOW, $hGUI_Child)
$i = 0
While GUIGetMsg() <> -3
    GUICtrlSetData($Progress1, Mod($i, 100))
    $i += 0.1
WEnd

_GDIPlus_GraphicsDispose ($_Image)
_GDIPlus_Shutdown()
Exit

Func _SetBitmap ( $hGUI, $hImage, $iOpacity, $n_width, $n_height )
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", $n_width )
DllStructSetData ( $tSize, "Y", $n_height )
$tSource = DllStructCreate ( $tagPOINT )
$pSource = DllStructGetPtr ( $tSource )
$tBlend = DllStructCreate ( $tagBLENDFUNCTION )
$pBlend = DllStructGetPtr ( $tBlend )
DllStructSetData ( $tBlend, "Alpha", $iOpacity )
DllStructSetData ( $tBlend, "Format", 1 )
_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 ;==> _SetBitmap ( )

Func _ImageResize ( $sInImage, $newW, $newH, $sOutImage = "" )
Local $oldImage, $GC, $newBmp, $newGC
If $sOutImage = "" Then _GDIPlus_Startup ( )
$oldImage = _GDIPlus_ImageLoadFromFile ( $sInImage )
$GC = _GDIPlus_ImageGetGraphicsContext ( $oldImage )
$newBmp = _GDIPlus_BitmapCreateFromGraphics ( $newW, $newH, $GC )
$newGC = _GDIPlus_ImageGetGraphicsContext ( $newBmp )
_GDIPlus_GraphicsDrawImageRect ( $newGC, $oldImage, 0, 0, $newW, $newH )
_GDIPlus_GraphicsDispose ( $GC )
_GDIPlus_GraphicsDispose ( $newGC )
_GDIPlus_ImageDispose ( $oldImage )
If $sOutImage = "" Then
Return $newBmp
Else
_GDIPlus_ImageSaveToFile ( $newBmp, $sOutImage )
_GDIPlus_BitmapDispose ( $newBmp )
_GDIPlus_Shutdown ( )
Return 1
EndIf
EndFunc ;==> _ImageResize ( )

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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