Sign in to follow this  
Followers 0
picea892

Alpha Blending

5 posts in this topic

Hi, Hoping someone would be kind enough to point me in the right direction on this. I have tweaked the launchy png that you can find on various post in the forum and was hoping to make it an underlay of many different icon pictures. (I have a Windows 7 script on the examples board I'm trying to spice up).

In the zip file is what I have to date. I think it is pretty self explantory. How would I make it so I had 5 or 6 launchy type png's all in a row. I am having some difficulties figuring out how to do this. Any help would be appreciated.

Picea

eyecandy.zip

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

... about transparent background of icons.

#include <GDIPlus.au3>
#include <GuiComboBox.au3>
#include <File.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <Array.au3>
#include <Winapi.au3>
#include<Misc.au3>
#include <Process.au3>
#include <StaticConstants.au3>
#include <GuiConstants.au3>
#include <ScreenCapture.au3>
#include <Constants.au3>

Global Const $AC_SRC_ALPHA = 1

_GDIPlus_Startup()
$pngSrc = @ScriptDir & "\LaunchySkin.png"
$hImage = _GDIPlus_ImageLoadFromFile($pngSrc)

; Extract image width and height from PNG
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
$GUI = GUICreate("", 100,100, 500, 500, $WS_POPUP, $WS_EX_LAYERED)
;$GUI2 = GUICreate("", 100, 100, 600, 500, $WS_POPUP, $WS_EX_LAYERED)
SetBitmap($GUI, $hImage, 0)
;SetBitmap($GUI2, $hImage, 0)
GUISetState()
WinSetOnTop($GUI, "", 1)
    SetBitmap($GUI, $hImage, 255)

$controlGui = GUICreate("ControlGUI", $width, $height, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI)
GUICtrlCreatePic(@ScriptDir & "\grey.gif", 0, 0, $width, $height)
GUICtrlSetState(-1, $GUI_DISABLE)
Run("notepad.exe","",@SW_MINIMIZE)
WinWait("Untitled - Notepad","")

$a = _ProcessGetIcon(_ProcessGetName (WinGetProcess ("Untitled - Notepad")))
        GUISetIcon($a)
        
$Icon = GUICtrlCreateIcon('', 0, 25, 30, 32, 32)
;GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
;GUICtrlSetColor(-1, 0xFFFFFF)
GUISetState()

SetIcon($Icon, 0x373737, $a, 0, 32, 32)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
    sleep(200)
WEnd
GUIDelete($controlGui)
;fade out png background
For $i = 255 To 0 Step -10
    SetBitmap($GUI, $hImage, $i)
Next
; Release resources
_WinAPI_DeleteObject($hImage)
_GDIPlus_Shutdown()


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



func SetIcon($controlID, $iBackground, $sIcon, $iIndex, $iWidth, $iHeight)
    
    const $STM_SETIMAGE = 0x0172

    local $tIcon, $tID, $hDC, $hBackDC, $hBackSv, $hBitmap, $hImage, $hIcon, $hBkIcon

    $tIcon = DllStructCreate('hwnd')
    $tID = DllStructCreate('hwnd')
    $hIcon = DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0)
    if (@error) or ($hIcon[0] = 0) then
        return SetError(1, 0, 0)
    endif
    $hIcon = DllStructGetData($tIcon, 1)
    $tIcon = 0
    $tID = 0

    $hDC = _WinAPI_GetDC(0)
    $hBackDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateSolidBitmap(0, $iBackground, $iWidth, $iHeight)
    $hBackSv = _WinAPI_SelectObject($hBackDC, $hBitmap)
    _WinAPI_DrawIconEx($hBackDC, 0, 0, $hIcon, 0, 0, 0, 0, $DI_NORMAL)
    
    _GDIPlus_Startup()
    
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    $hBkIcon = DllCall($ghGDIPDll, 'int', 'GdipCreateHICONFromBitmap', 'hWnd', $hImage, 'int*', 0)
    _GDIPlus_ImageDispose($hImage)
    
    GUICtrlSendMsg($controlID, $STM_SETIMAGE, $IMAGE_ICON, $hBkIcon[2])
    _WinAPI_RedrawWindow(GUICtrlGetHandle($controlID))
    
    _GDIPlus_Shutdown()
    
    _WinAPI_SelectObject($hBackDC, $hBackSv)
    _WinAPI_DeleteDC($hBackDC)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteObject($hIcon)

    return SetError(0, 0, 1)
endfunc; SetIcon

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


Func _ProcessGetIcon($vProcess)
    Local $iPID = ProcessExists($vProcess)
    If Not $iPID Then Return SetError(1, 0, -1)
    Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If Not IsArray($aProc) Or Not $aProc[0] Then Return SetError(2, 0, -1)
    Local $vStruct = DllStructCreate('int[1024]')
    Local $hPsapi_Dll = DllOpen('Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll')
    If $hPsapi_Dll = -1 Then Return SetError(3, 0, '')
    DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _
    'hwnd', $aProc[0], _
    'ptr', DllStructGetPtr($vStruct), _
    'int', DllStructGetSize($vStruct), _
    'int_ptr', 0)
    Local $aRet = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _
    'hwnd', $aProc[0], _
    'int', DllStructGetData($vStruct, 1), _
    'str', '', _
    'int', 2048)
    DllClose($hPsapi_Dll)
    If Not IsArray($aRet) Or StringLen($aRet[3]) = 0 Then Return SetError(4, 0, '')
    Return $aRet[3]
EndFunc

Your idea is good.

:D

Edited by Yashied

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Very nicely done Yashied. Thank you. If I could have guessed that this was possible I would have asked how to make the icon background transparent. If I haven't said it yet on this forum. I am honestly starting believe anything is possible in Autoit.

At 32x32 it looks really good. If you up it to 64x64 you can see some inconsistencies around the edges on a white background. If you put a dark background down, looks good. I have my Opera Icon up and it's pretty neat because it's an O so you can see through the center of it....

Thanks again, I'm going to have to play with this.....

Picea

Edited by picea892

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi Yashied or anyone else who can help.

I really like the look of the icons that your script produces. Got thinking about it and think that stretching the launchy png will serve my needs. Still looks good and can be resized on the fly based on number of icons I have need for. Using the Stretch script from this post:

http://www.autoitscript.com/forum/index.ph...;hl=stretch+png

I can make a slick looking background but it seems to break your script. I'm not sure that it's really the fault of your script, more probably from my lack of understanding on this topic. Why is this line bombing out in your script:

_WinAPI_DrawIconEx($hBackDC, 0, 0, $hIcon, 0, 0, 0, 0, $DI_NORMAL)

Attached is the tweaked example

stretch.au3

Edited by picea892

Share this post


Link to post
Share on other sites

Oh......I got it working. I think I had some typos. Boy it`s sweet.... Thank you so much for the help :D

newway.au3

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