Jump to content

GUI 50% transparency without affecting the image


Go to solution Solved by mutleey,

Recommended Posts

Posted

I've been messing with this script for hours and haven't been successful, I wanted to leave the GUI with 50% transparency without affecting the png image.

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

Global Const $STM_SETIMAGE = 0x0172

_GDIPlus_Startup()

Global $hGUI = GUICreate("", 300, 300, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
GUISetBkColor(0xABCDEF)

Local $pic = GUICtrlCreatePic("", 50, 50, 200, 200)

$hImage = _GDIPlus_BitmapCreateFromFile(@ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_GDIPlus_BitmapDispose($hImage)

WinSetTrans($hGUI, "", 127)

GUISetState(@SW_SHOW)


__GUICtrlSendMsg($pic, $hBitmap)


Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE


GUIDelete()
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_BitmapDispose($hImage)
_GDIPlus_Shutdown()


Func __GUICtrlSendMsg($picCtrl, $imgPic)
    Local $msgRtrn = GUICtrlSendMsg($picCtrl, $STM_SETIMAGE, $IMAGE_BITMAP, $imgPic)
    If $msgRtrn Then
        DllCall("gdi32.dll", "bool", "DeleteObject", "handle", $msgRtrn)
    EndIf
EndFunc   ;==>__GUICtrlSendMsg

 

Posted (edited)

It doesn't. What are you talking about?

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

$g_hGUI = GUICreate("Test", 250, 250, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW))

_GDIPlus_Startup()

$g_hImage = _GDIPlus_ImageLoadFromFile(@ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png")
$g_aDim = _GDIPlus_ImageGetDimension($g_hImage)
$hImagetemp = _GDIPlus_BitmapCreateFromScan0($g_aDim[0], $g_aDim[1])
$hContext = _GDIPlus_ImageGetGraphicsContext($hImagetemp)
_GDIPlus_GraphicsClear($hContext, 0xFFABCDEF)

$hAttribute_Alpha = _GDIPlus_ImageAttributesCreate()
$tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0, 0, 0, -0.85) ;0 = opaque, -1 = transparent
_GDIPlus_ImageAttributesSetColorMatrix($hAttribute_Alpha, 0, True, DllStructGetPtr($tColorMatrix))

$g_hImage2 = _GDIPlus_BitmapCreateFromScan0($g_aDim[0], $g_aDim[1])
$g_hGfx = _GDIPlus_ImageGetGraphicsContext($g_hImage2)

_GDIPlus_GraphicsDrawImageRectRect($g_hGfx, $hImagetemp, 0, 0, $g_aDim[0], $g_aDim[1], 0, 0, $g_aDim[0], $g_aDim[1], $hAttribute_Alpha)
_GDIPlus_GraphicsDrawImageRect($g_hGfx, $g_hImage, 10, 10, 200, 200)


SetBitmap($g_hGUI, $g_hImage2, 255)
GUISetState()

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_GraphicsDispose($hContext)
_GDIPlus_ImageAttributesDispose($hAttribute_Alpha)
_GDIPlus_ImageDispose($g_hImage)
_GDIPlus_ImageDispose($g_hImage2)
_GDIPlus_BitmapDispose($hImagetemp)
_GDIPlus_GraphicsDispose($g_hGfx)
_GDIPlus_Shutdown()

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", 1)
    _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

 

Edited by Andreik
Posted (edited)

@Andreik for some reason it's not becoming transparent, it has a black background, I suspect it's something in my autoit installation (or my pc)... I'll reinstall it to see if that's it.

Edited by mutleey
  • Solution
Posted (edited)

I'm going to reinstall my autoit, if the problem persists I'll research the forum further, thank you for the support.

EDIT:

@Andreik Problem solved, I reinstalled autoit and it didn't solve it... I reinstalled directx and visual c++ and it went back to normal, now both your example and the UEZ one are working perfectly.

Edited by mutleey

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
  • Recently Browsing   0 members

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