Jump to content

Transparent Image over a Button


Recommended Posts

Hi!

I am searching for a way to display a transparent image (or Icon) over an Button. And the image should always stay on top.


Here is what i have so far:
At script start the picture is over the button..but if you move the mouse over the button it overlaps the image.
And if i add $GUI_ONTOP to the picture, the transparency is gone :(

Maybe someone has an idea..

Thanks in advance!
 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WinAPIIcons.au3>
#include <WinAPIShellEx.au3>




GUICreate("GUI", 300, 300)


$hbutton = GUICtrlCreateButton("This is a button", 20, 40, 150, 30,$WS_CLIPSIBLINGS)

$hpic =  GUICtrlCreatePic("", 10, 10, 128, 128)
_SetIconAlpha($hpic,"shell32.dll", 12,128,128)
GUICtrlSetState(-1, $GUI_DISABLE)
;~ GUICtrlSetState(-1,$GUI_ONTOP) ;If you uncomment this..the picture is on top...but the transparency is gone :(


GUISetState()




While 1
        $Msg = GUIGetMsg()
        If $Msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd




Func _SetIconAlpha($hWnd, $sIcon, $iIndex, $iWidth, $iHeight)

    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
        If $hWnd = 0 Then
            Return SetError(1, 0, 0)
        EndIf
    EndIf

    If $iIndex <> 0 Then $iIndex = $iIndex - 1
    Local $hIcon = _WinAPI_ShellExtractIcon($sIcon, $iIndex, $iWidth, $iHeight)

    If $hIcon = 0 Then
        Return SetError(1, 0, 0)
    EndIf

    Local $hBitmap, $hObj, $hDC, $hMem, $hSv

    $hDC = _WinAPI_GetDC($hWnd)
    $hMem = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    $hSv = _WinAPI_SelectObject($hMem, $hBitmap)
    _WinAPI_DrawIconEx($hMem, 0, 0, $hIcon, $iWidth, $iHeight, 0, 0, 2)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_SelectObject($hMem, $hSv)
    _WinAPI_DeleteDC($hMem)
    _WinAPI_DestroyIcon($hIcon)
    _WinAPI_DeleteObject(_SendMessage($hWnd, 0x0172, 0, 0))
    _SendMessage($hWnd, 0x0172, 0, $hBitmap)
    $hObj = _SendMessage($hWnd, 0x0173)
    If $hObj <> $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
    EndIf
    Return 1
EndFunc   ;==>_SetIconAlpha

 

Link to comment
Share on other sites

Sorry just saw i created the thread in the wrong forum. :sweating:
Please can someone move this thread to "AutoIt General Help and Support".

PS: Thanks for moving!

Edited by ISI360
Link to comment
Share on other sites

Hmm sadly no. The image in this case should not "be" the button. It should only stay over (and beyond) it.

I tell you the "background" of this stuff. Of course it´s about my ISN AutoIt Studio. Here i am using little icons in nearly every buttons.
Thes icons are set to the button via an ImageList ($BCM_SETIMAGELIST), which works very well and as it should.

So as you may know, the ISN also uses a Skin System. (The USkin UDF. I know its dead and buggy..anyhow i think its the best skin system available for autoit at the monent)
And when USkin is enabled, it kills every Icons on Buttons which are assigned thourgh an imagelist. (Its a bug/error in Uskin)
And ever "Add icon to button"-code i found at the moment adds icons with imagelists.
So now i am searching for a way to restore (or build around) with something to recreate those icons in the buttons.

I tried _GUICtrlButton_SetImage, which works with USkin...but with not text possible at the same time. 
And my other idea was to simply "draw" an icon over the button which should stay over there. Which brings me here ^^
 

Edited by ISI360
Link to comment
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
 Share

×
×
  • Create New...