Jump to content
Sign in to follow this  
ISI360

Transparent Image over a Button

Recommended Posts

ISI360

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

 

Share this post


Link to post
Share on other sites
ISI360

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

Share this post


Link to post
Share on other sites
UEZ

Does this help you?

 


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
ISI360

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

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  

  • Similar Content

    • Sven-Seyfert
      By Sven-Seyfert
      Hi Community,

      I'm looking for a way to do a Video Overlay GUI or something like that. The idea is to create a GUI which plays a video loop (with transparency/alpha channel) in front of an other GUI. Before you asking why - because I don't believe that GDIPlus can do it out of the box. My skillset for that kind of graphical things isn't good enough to do that, but here are some specialist like @UEZ maybe who can help.

      Example alpha channel video (visualized as animated *.gif):

      I tried to do the light rays effect directly with GDIPlus, but honestly that's a bit too difficult for me. I would be very glad and grateful if there are some suggestions, ideas or recommendations.

      Code for the Video play:
       
      Example video "End.mpeg":
       
      The next challenge is that the overlay GUI should be not clickable. If I hover over the overlay area, I want to have the possibility to control the GUI or what ever, in the background. But if there is any chance to make it with GDIPlus as a Video Overlay for light rays, I would prefer that approach instead of my crazy work-around idea.

      Thanks for any suggestion - I'm grateful!
      Sven
    • aiter
      By aiter
      I am trying to get an image showing through a edit box.  I am only successful in making the edit box totally transparent
      #include-once #include <GUIConstants.au3> #include <GDIPlus.au3> #include <WinAPISys.au3> #include <colorconstants.au3> ;WS_EX_TRANSPARENT $gui = GUICreate("", 1000, 800, -1, -1, -1 , $WS_EX_LAYERED) ; use layered to get _winapi_setlay... to work $pic = GUICtrlCreatePic("c:\Program Files (x86)\AutoIt3\Examples\GUI\Merlin.gif", 0,0,1000, 800) GUICtrlSetState(-1, $GUI_DISABLE) $edit = GUICtrlCreateEdit("First line" & @CRLF, 176, 32,200,600) GUICtrlSetBkColor(-1,$COLOR_YELLOW) _WinAPI_SetLayeredWindowAttributes($gui,$COLOR_YELLOW,199) ; 199 is alpha (transparency level) GUISetState(@SW_SHOW,$gui) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else EndSelect WEnd Exit Func Terminate() exit(0) EndFunc So I am making the edit box's background yellow then using the _WINAPI_SetLayeredWIndowAttributes command to make the yellow disappear (which it does), but the alpha level is supposed to give a bit of opaqueness to it, but its not, just making it totally transparent.  The alpha level is in fact affecting the window itself and not the edit box. I only want the edit box to be partially transparent.
      Help appreciated.
       
    • Skeletor
      By Skeletor
      Hi All,
      I know many newbies search for this feature.
      I decided to share this piece of code with everyone.
      Basically its a "splash screen" that has a transparent image.
      In a nutshell - Gui with a transparent gif.
      Enjoy...
      Download attachment....
       
      Splash Screen GUI.zip
    • Chimp
      By Chimp
      Hi
      Is it possible to draw using a semitransparent paint?
      In short, I would like to paint on a Label control that contains text, and at the same time be able to see through the paint, so to see the text behind.
      Something like using an highlighter.
      Only to show the effect that I would achieve, here are two listings. The first, using transparency on the whole gui, allows to draw an ellipse into the gui's body showing at the same time what's beneath the ellipse's border. (the inner of the ellipse should be totally transparent.) Click on the GUI and drag to draw the ellipse.
      #include <Misc.au3> ; for _IsPressed (01 Left mouse button) #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <WinAPIGdi.au3> Opt("MouseCoordMode", 0) Global $hUser32dll = DllOpen("user32.dll") ; for _IsPressed Local $aPos ; -- Create the GUI ------------------------------- Global $hGUI = GUICreate("Preview of an ellipse (click and drag to draw)", 400, 400, 100, 100, -1, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) Local $iTransparent = 0x0FF0FF ; tansparent color ; This sets which color to be transparent and opacity of the whole window _WinAPI_SetLayeredWindowAttributes($hGUI, $iTransparent, 127) ; last param opacity intensity: 0 totally transp, 255 NOT transp GUISetBkColor($iTransparent, $hGUI) ; background becomes transparent GUISetState(@SW_SHOW) ; MAIN LOOP While 1 $aPos = MouseGetPos() $aMsg = GUIGetMsg($GUI_EVENT_ARRAY) ; $GUI_EVENT_ARRAY -> returns an array containing the event and extended information Select Case $aMsg[0] = $GUI_EVENT_CLOSE ConsoleWrite("Bye" & @LF) Exit ; End() EndSelect If _IsPressed("01", $hUser32dll) Then ; draw the ellipse following mouse position. ; returns only when left mouse button is released _Preview_Ellipse($hGUI, $aPos[0], $aPos[1], 24) EndIf WEnd Func _Preview_Ellipse($hGUIx, $iX, $iY, $iPenSize = 9, $iColor = 0xFF0000, $iFill = 0x0FF0FF) ; Creates $tagRECT structure with the coordinates of the specified rectangle Local $tRECT = _WinAPI_CreateRect($iX, $iY, $iX, $iY) Local $hDC = _WinAPI_GetWindowDC($hGUIx) Local $hPen = _WinAPI_CreatePen($PS_SOLID, $iPenSize, $iColor) ; border size and color Local $hBrush = _WinAPI_CreateBrushIndirect($BS_SOLID, $iFill) ; fill color Local $hObj1 = _WinAPI_SelectObject($hDC, $hBrush) Local $hObj2 = _WinAPI_SelectObject($hDC, $hPen) Local $aPreviousPos[2], $aPos[2] While _IsPressed("01", $hUser32dll) ; stay here till left mouse button is released ; get the mouse coordinates: ; $aPos[0] = X coord (horizontal), $aPos[1] = Y coord (vertical) $aPos = MouseGetPos() ; if mouse has mooved then redraw the ellipse accordingly If $aPreviousPos[0] <> $aPos[0] Or $aPreviousPos[1] <> $aPos[1] Then ; mouse has mooved ; take track of new mouse position $aPreviousPos[0] = $aPos[0] $aPreviousPos[1] = $aPos[1] ; DllStructSetData($tRECT, 1, $iX) ; initial point is fixed ; DllStructSetData($tRECT, 2, $iY) DllStructSetData($tRECT, 3, $aPos[0]) ; new mouse position DllStructSetData($tRECT, 4, $aPos[1]) ; erase content of the gui (erase the previous ellipse) _WinAPI_RedrawWindow($hGUIx, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE, $RDW_UPDATENOW)) ; Draws the new ellipse (based on new mouse position) _WinAPI_Ellipse($hDC, $tRECT) EndIf ; WEnd ; if left button is released then exit ; free resources _WinAPI_SelectObject($hDC, $hObj1) _WinAPI_SelectObject($hDC, $hObj2) _WinAPI_DeleteObject($hPen) _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC($hGUIx, $hDC) _WinAPI_RedrawWindow($hGUIx, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE, $RDW_UPDATENOW)) ; erase content of the gui EndFunc ;==>_Preview_Ellipse  
      This second listing is a botched attempt to achieve the same effect on a Label control located on a normal window (not transparent).
      #include <Misc.au3> ; for _IsPressed (01 Left mouse button) #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <WinAPIGdi.au3> Opt("MouseCoordMode", 0) Global $hUser32dll = DllOpen("user32.dll") ; for _IsPressed Local $aPos ; -- Create the GUI ------------------------------- Global $hGUI = GUICreate("Preview of an ellipse (click and drag to draw)", 400, 400, 100, 100) ; , -1, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) ; Label Local $s = StringReplace(StringFormat('%22s', ""), " ", "the quick brown fox jumps over the lazy dog ") Local $hLabel = GUICtrlGetHandle(GUICtrlCreateLabel($s, 10, 10, 250, 250)) GUICtrlSetBkColor(-1, 0xAAAA00) ; Local $iTransparent = 0x0FF0FF ; tansparent color ; This sets which color to be transparent and opacity of the whole window ; _WinAPI_SetLayeredWindowAttributes($hGUI, $iTransparent, 127) ; last param opacity intensity: 0 totally transp, 255 NOT transp ; GUISetBkColor($iTransparent, $hGUI) ; background becomes transparent GUISetState(@SW_SHOW) ; MAIN LOOP While 1 $aPos = MouseGetPos() $aMsg = GUIGetMsg($GUI_EVENT_ARRAY) ; $GUI_EVENT_ARRAY -> returns an array containing the event and extended information Select Case $aMsg[0] = $GUI_EVENT_CLOSE ConsoleWrite("Bye" & @LF) Exit ; End() EndSelect If _IsPressed("01", $hUser32dll) Then ; draw the ellipse following mouse position. ; returns only when left mouse button is released _Preview_Ellipse($hLabel, $aPos[0], $aPos[1], 24) EndIf WEnd Func _Preview_Ellipse($hGUIx, $iX, $iY, $iPenSize = 9, $iColor = 0xFF0000, $iFill = 0x0FF0FF) ; Creates $tagRECT structure with the coordinates of the specified rectangle Local $tRECT = _WinAPI_CreateRect($iX, $iY, $iX, $iY) Local $hDC = _WinAPI_GetWindowDC($hGUIx) Local $hPen = _WinAPI_CreatePen($PS_SOLID, $iPenSize, $iColor) ; border size and color Local $hBrush = _WinAPI_CreateBrushIndirect($BS_SOLID, $iFill) ; fill color Local $hObj1 = _WinAPI_SelectObject($hDC, $hBrush) Local $hObj2 = _WinAPI_SelectObject($hDC, $hPen) Local $aPreviousPos[2], $aPos[2] While _IsPressed("01", $hUser32dll) ; stay here till left mouse button is released ; get the mouse coordinates: ; $aPos[0] = X coord (horizontal), $aPos[1] = Y coord (vertical) $aPos = MouseGetPos() ; if mouse has mooved then redraw the ellipse accordingly If $aPreviousPos[0] <> $aPos[0] Or $aPreviousPos[1] <> $aPos[1] Then ; mouse has mooved ; take track of new mouse position $aPreviousPos[0] = $aPos[0] $aPreviousPos[1] = $aPos[1] ; DllStructSetData($tRECT, 1, $iX) ; initial point is fixed ; DllStructSetData($tRECT, 2, $iY) DllStructSetData($tRECT, 3, $aPos[0]) ; new mouse position DllStructSetData($tRECT, 4, $aPos[1]) ; erase content of the gui (erase the previous ellipse) _WinAPI_RedrawWindow($hGUIx, $tRECT, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE, $RDW_UPDATENOW)) ; Draws the new ellipse (based on new mouse position) _WinAPI_Ellipse($hDC, $tRECT) EndIf ; WEnd ; if left button is released then exit ; free resources _WinAPI_SelectObject($hDC, $hObj1) _WinAPI_SelectObject($hDC, $hObj2) _WinAPI_DeleteObject($hPen) _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC($hGUIx, $hDC) _WinAPI_RedrawWindow($hGUIx, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE, $RDW_UPDATENOW)) ; erase content of the gui EndFunc ;==>_Preview_Ellipse I'm sure to be on the wrong way (I admit my knowledge on graphics is close to zero)
      How can I achieve that effect?
      Thanks on advance for any help.
    • Simpel
      By Simpel
      Hi,
      I'm trying to create a console reader. All is working but I have a problem with the look. I want the line numbers with another backgroundcolor in silver. I made this with a small silver label. The edit control over the label has a transparent background.
      But if I start the prog then i can see how the line numbers wipe the silver background off. And if I click into the Edit then the silver label disappears completely.
      #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> #include <StaticConstants.au3> #include <GuiEdit.au3> Opt("GUIOnEventMode", 1) Global $g_iZaehler = 0 Global $g_hGUI = GUICreate("Console: StdoutRead" , 800, 800, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPCHILDREN, $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Global $text = GUICtrlCreateEdit("",10,30,780,760, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_READONLY + $ES_NOHIDESEL) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $g_LaZeilen = GUICtrlCreateLabel("Zeilen: " & StringFormat("% 5d", $g_iZaehler), 680, 10, 100, 9, $SS_LEFTNOWORDWRAP) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKSIZE) Global $g_hCbFreeze = GUICtrlCreateCheckbox("&Freeze", 13, 5, 90) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlCreateLabel("", 11, 31, 42, 758) ; soll die Ziffern andersfarbig hinterlegen GUICtrlSetBkColor(-1, $COLOR_SILVER) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) GUISetState(@SW_SHOW) Global $sText = StringFormat("% 5d", $g_iZaehler) & @CRLF _GUICtrlEdit_AppendText($text, $sText) While 1 Sleep(200) $g_iZaehler += 1 $sText = StringFormat("% 5d", $g_iZaehler) & @CRLF _GUICtrlEdit_AppendText($text, $sText) WEnd Func _Exit() Exit EndFunc Do you have any suggestions.
      Regards, Conrad
×