Jump to content

GUI transparency and gradient effect


Recommended Posts

Hi -

I'm trying to apply transparency and gradient effect (to the bottom) to a GUI at the same time. I've searched the forum and could found some topics about my issue - but non of them seems to combine both. Playing around with _WinAPI_SetLayeredWindowAttributes() and PNG images (bad for different screen resolutions) was good to imitate gradient effect - WinSetTrans() helped my to set transparency. How can both be combined?

Here's what I started with (w/ transparency only):

#include <GUIConstantsEx.au3>
#include <GUIEdit.au3>
#include <WindowsConstants.au3>


Local $hGUI = GUICreate("TEST", @DesktopWidth, @DesktopHeight - 100, 0, 0, $WS_POPUP)
Local $hEdit1 = GUICtrlCreateEdit("", 100, 100, 100, 100, $ES_READONLY, $WS_EX_TRANSPARENT)


_GUICtrlEdit_AppendText($hEdit1, "Text1" & @CRLF)
_GUICtrlEdit_AppendText($hEdit1, "Text2" & @CRLF)
_GUICtrlEdit_AppendText($hEdit1, "Text3" & @CRLF)
GUICtrlSetBkColor($hEdit1, 0x0F4F8F)
GUICtrlSetColor($hEdit1, 0x4F8FCF)
GUICtrlSetFont($hEdit1, 20.0, 400, 0, "Courier New", 2)
GUISetBkColor(0x0F4F8F, $hGUI)
WinSetTrans($hGUI, "", 200)
GUISetState(@SW_SHOW, $hGUI)


Local $aMsg
While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $hGUI
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    ExitLoop
            EndSwitch
    EndSwitch
WEnd


GUIDelete($hGUI)

Is there a solution?

-supersonic.

Edited by supersonic
Link to comment
Share on other sites

I've found some more examples ( e. g. '?do=embed' frameborder='0' data-embedContent>> + https://autoit.de/index.php/Thread/24118-PNG-als-Gui-Transparent/ ) pointing me - at least I guess - in the right direction:

#include <GUIConstantsEx.au3>
#include <GUIEdit.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>


Global $hGUI


; PART 1
$hGUI = GUICreate("TEST", @DesktopWidth, @DesktopHeight - 100, 0, 0, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST)
GUISetBkColor(0xABCDEF, $hGUI)
GUISetState(@SW_SHOW, $hGUI)
_WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 0xAA, 3)


; PART 2
_GDIPlus_Startup()
Global $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\test.png")
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
;~ _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, @DesktopWidth, @DesktopHeight - 100)


Global $hEdit = GUICtrlCreateEdit("Edit1", 200, 200, 200, 200, $ES_READONLY, $WS_EX_TRANSPARENT)


GUIRegisterMsg($WM_PAINT, "_WM_PAINT")


Global $iMsg
While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()


Func _WM_PAINT($hWnd, $Msg, $wParam, $lParam)
;~  _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, @DesktopWidth, @DesktopHeight - 100)
    _WinAPI_RedrawWindow($hGUI, 0, 0, 1)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_PAINT

But there's still something wrong with the script. Somehow the alpha channel of the PNG seems to be ignored!? If swapping part 1 with part 2 the right effect appears until the image is completely shown - then the image disappears.

Someone any ideas?

post-34380-0-68231200-1424173914_thumb.p

Edited by supersonic
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...