mutleey Posted November 23, 2023 Posted November 23, 2023 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. expandcollapse popup#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
Andreik Posted November 23, 2023 Posted November 23, 2023 This question and few similar has been answered several times on the forum. Just use the search. mutleey 1
mutleey Posted November 23, 2023 Author Posted November 23, 2023 @Andreik I read this topic, but it's not what I wanted to do, I thought it could be done in the GUI directly without affecting the PNG.
Andreik Posted November 23, 2023 Posted November 23, 2023 (edited) It doesn't. What are you talking about? expandcollapse popup#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 November 23, 2023 by Andreik mutleey 1
mutleey Posted November 23, 2023 Author Posted November 23, 2023 (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 November 23, 2023 by mutleey
mutleey Posted November 23, 2023 Author Posted November 23, 2023 The one in the first post is working with transparency, the one in UEZ has a black background, which is why I didn't get it as a base.
Andreik Posted November 23, 2023 Posted November 23, 2023 I posted the modified code above to fit your request. Anyway this question and many variations of this has been answered multiple times on the forum. mutleey 1
Solution mutleey Posted November 23, 2023 Author Solution Posted November 23, 2023 (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 November 23, 2023 by mutleey
Andreik Posted November 23, 2023 Posted November 23, 2023 Strange but glad that you found a solution.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now