Sign in to follow this  
Followers 0
Slym

lod3n + PNG transparent in it ?

2 posts in this topic

#1 ·  Posted (edited)

Hi,

I'm using the great lod3n launcher but i can't find a way to draw a transparent PNG on it (actually i don't even know if it's possible). I looked all over this forum without success.

I try tu use a transparent PNG as a button in my transparent GUI.

The transparent GUI is working fine (thanks again to lod3n script) but when i draw a transparent PNG on it everything becomes a mess.

I'm not a master at AutoIT so maybe i'm just doing something wrong.

Could someone tell me what's wrong in my code ?

Thank you

lod3n_launcher.zip

Edited by Slym

--------------------- [font="Franklin Gothic Medium"]LinuxLive USB Creator[/font], [size="3"]The only Linux Live USB creator with easy integrated virtualization (made with AutoIT)[/size] ---------------------

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

First things first.... you took a great piece of code and hacked it to death with one thing after another.

We all have to learn sometime but, when doing so make one change at a time until you get the results you want.

I do not have the patience or time to clean up your code, but I think I got the results you were looking for.

Replace your code with this:

; Special thanks to GaryFrost for updating this to work with AutoIt v3.2.12.0!

#NoTrayIcon
#include <GDIPlus.au3>; this is where the magic happens, people
#Include <WinAPI.au3>
#include <GuiComboBox.au3>
#include <File.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
Opt("MustDeclareVars", 0)

Global Const $AC_SRC_ALPHA = 1
;~ Global Const $ULW_ALPHA       = 2
Global $old_string = "", $runthis = ""
Global $launchDir = @DesktopDir

; Load PNG file as GDI bitmap
_GDIPlus_Startup()
$pngSrc = @ScriptDir & "\LaunchySkin.png"
$hImage = _GDIPlus_ImageLoadFromFile($pngSrc)
$WIFIpngSrc = @ScriptDir & "\wifi.png"
$WIFI_Image = _GDIPlus_ImageLoadFromFile($WIFIpngSrc)

; Extract image width and height from PNG
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)

; Create layered window
$GUI = GUICreate("lod3n launcher", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
SetBitmap($GUI, $hImage, 255)
; Register notification messages
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

GUISetState()
WinSetOnTop($GUI, "", 1)

; create child MDI gui window to hold controls
; this part could use some work - there is some flicker sometimes...
$controlGui = GUICreate("ControlGUI", $width, $height, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI)

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($controlGui)

; child window transparency is required to accomplish the full effect, so $WS_EX_LAYERED above, and
; I think the way this works is the transparent window color is based on the image you set here:
GUICtrlCreatePic(@ScriptDir & "\grey.gif", 0, 0, $width, $height)
GUICtrlSetState(-1, $GUI_DISABLE)

; just a text label
;GUICtrlCreateLabel("Type the name of a file on your desktop and press Enter", 100, 186, 140, 50)

$combo = GUICtrlCreateCombo("-> Choisir une clé USB", 100,10, 200,20)
;GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
;GUICtrlSetColor(-1, 0xFFFFFF)

;---------------------------------------- HERE IS MY PROBLEM ---------------------------------------------------------------
;$hPic = GUICtrlCreatePic("", 10,10 , 256, 256)
;_GUICtrlStatic_SetPicture("wifi.png", $hPic)

GUISetState()

_GDIPlus_GraphicsDrawImageRectRect ($hGraphic, $WIFI_Image, 0,0,30,30,35,5,30,30)


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd




GUIDelete($controlGui)


; Release resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ImageDispose($WIFI_Image)
_GDIPlus_Shutdown()





; ====================================================================================================




; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image.
; ====================================================================================================




Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $GUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc ;==>WM_NCHITTEST

; ====================================================================================================




; SetBitMap
; ====================================================================================================




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 ;==>SetBitmap


; I don't like AutoIt's built in ShellExec. I'd rather do the DLL call myself.
Func _ShellExecute($sCmd, $sArg = "", $sFolder = "", $rState = @SW_SHOWNORMAL)
    $aRet = DllCall("shell32.dll", "long", "ShellExecute", _
            "hwnd", 0, _
            "string", "", _
            "string", $sCmd, _
            "string", $sArg, _
            "string", $sFolder, _
            "int", $rState)
    If @error Then Return 0

    $RetVal = $aRet[0]
    If $RetVal > 32 Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc ;==>_ShellExecute

Func _GUICtrlStatic_SetPicture($File, $CtrlId)
       $hImage = _GDIPlus_ImageLoadFromFile($File)
       $hScrDC  = _WinAPI_GetDC(0)
       $hMemDC  = _WinAPI_CreateCompatibleDC($hScrDC)
       $hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
       GUICtrlSetImage($CtrlId, "")
      _SetBitmapToCtrl($CtrlId, $hBitmap2)
EndFUnc

Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)

      ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)

        Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc

And replace the "wifi.png" with the one below.

EDIT: I removed any semi transparent channel from the png. It is either full opacity or completely transparent.

post-35258-1228527191_thumb.png

Edited by JustinMeyer

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