Sign in to follow this  
Followers 0
FaridAgl

GUICtrlCreateIcon() with transparent background

3 posts in this topic

#include <GUIConstantsEx.au3>

GUICreate("", 720, 480)
Global $LABLE_BACKGROUND = GUICtrlCreateLabel("", 0, 0, 100, 100)
GUICtrlSetBkColor(-1, 0x007ACC)
GUICtrlCreateIcon("shell32.dll", 9, 25, 25, 32, 32)
;GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ;It doesn't help
GUISetState()

AdlibRegister(Foo, 500)
Do
Until (GUIGetMsg() = $GUI_EVENT_CLOSE)

Func Foo()
    Local Static $i = 0
    $i += 1

    Switch ($i)
        Case 1
            GUICtrlSetBkColor($LABLE_BACKGROUND, 0x007ACC)
        Case 2
            GUICtrlSetBkColor($LABLE_BACKGROUND, 0xD24726)
        Case 3
            GUICtrlSetBkColor($LABLE_BACKGROUND, 0x66217A)
        Case 4
            GUICtrlSetBkColor($LABLE_BACKGROUND, 0x719C51)
            $i = 0
    EndSwitch
EndFunc

Share this post


Link to post
Share on other sites



OK, I just found a workaround using PNGs, fair enough.

#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>

Global Const $STM_SETIMAGE = 0x0172

_GDIPlus_Startup()
Global $hImage = _GDIPlus_ImageLoadFromFile("New Account.png")
Global $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

GUICreate("", 720, 480)

Global $lblBackground = GUICtrlCreateLabel("", 0, 0, 100, 100)
GUICtrlSetBkColor(-1, 0x007ACC)

Global $lblImage = GUICtrlCreatePic("", 25, 25, 16, 16)
_WinAPI_DeleteObject(GUICtrlSendMsg($lblImage, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap))

GUISetState()

AdlibRegister(Foo, 500)
Do
Until (GUIGetMsg() = $GUI_EVENT_CLOSE)
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

Func Foo()
    Local Static $i = 0
    $i += 1

    Switch ($i)
        Case 1
            GUICtrlSetBkColor($lblBackground, 0x007ACC)
        Case 2
            GUICtrlSetBkColor($lblBackground, 0xD24726)
        Case 3
            GUICtrlSetBkColor($lblBackground, 0x66217A)
        Case 4
            GUICtrlSetBkColor($lblBackground, 0x719C51)
            $i = 0
    EndSwitch
EndFunc

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here we go, just make sure to call _GDIPlus_Startup() before calling this function:

Func GUICtrlCreatePicEx($sFileName, $iLeft, $iTop, $iWidth, $iHeight, $iStyle = -1, $iExStyle = -1)
    Local Const $STM_SETIMAGE = 0x0172

    Local $hImage = _GDIPlus_ImageLoadFromFile($sFileName)
    If (@error) Then Return 0

    Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    If (@error) Then
        _GDIPlus_ImageDispose($hImage)
        Return 0
    EndIf

    _GDIPlus_ImageDispose($hImage)

    Local $iCtrlId = GUICtrlCreatePic("", $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle)

    Local $hPreviousBitmap = GUICtrlSendMsg($iCtrlId, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
    If ($hPreviousBitmap <> 0) Then _WinAPI_DeleteObject($hPreviousBitmap)
    _WinAPI_DeleteObject($hBitmap)

    Return $iCtrlId
EndFunc
Edited by D4RKON3

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