Jump to content

Translucent color (not just WinAPI_DeleteObject) GUI elements


Go to solution Solved by UEZ,

Recommended Posts

Hello everyone,

I was wondering if you can point me into the right direction for my problem: I want a color-translucent GUI - I know how to cut holes into my GUI / extract shapes from it using _WinAPI_*RGN und _WinAPI_DeleteObject, but this is not exactly what I need. I want the cut out to be translucent in a color, e.g. blue. An example of this effect is given by the image at 

http://3.bp.blogspot.com/-fPTdkUUQp_Q/ULtd5P7y62I/AAAAAAAAAuA/kXSEVCuIKK0/s1600/TranslucentPanel4.png

Where do I have to look?

All the best,

Chris

PS: WinSetTrans ( "title", "text", transparency ) does not quite the trick - I don't want the full window to be translucent, but just a part. Any ideas how I can achieve that with WinSetTrans are also highly welcome!

Edited by SlowSheep
Link to comment
Share on other sites

Thanks Tekk, this looks promising. I looked up the example and found this, see attached screenshot. http://abload.de/image.php?img=blurxvzux.png

Unfortunately, it blurs the text under it;

there is a WinAPI_DwmSetColorizationParameters ( $tDWMCP ) function taking a 

$tDWMCP $tagDWM_COLORIZATION_PARAMETERS containing the colorization parameters to be set.

 

which is 

"dword Color;dword AfterGlow;uint ColorBalance;uint AfterGlowBalance;uint BlurBalance;uint GlassReflectionIntensity; uint OpaqueBlend;"

 

do I have to create this using

DllStructSetData($a, "var1", -1)

and then pass it?

Link to comment
Share on other sites

The images in post#1 seem to be semi transparent.

You can use this function to display the images

Func SetTransparentBitmap($hGUI, $hImage, $iOpacity = 0xFF)
    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,  $hMemDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>SetTransparentBitmap 

Br,

UEZ

Edited by UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

On second look, perhaps this is not Aero Glass.  The border and lighter color at the top don't seem to match the Aero effect.  I'm also not sure you can turn the blur off for this.  UEZ may be on to something.  Perhaps these are semitransparent images.  I retract my suggestion. 

However, to answer your question.  Yes, you would create the $tDWMCP structure, set the required field to your value and then pass that structure to _WinAPI_DwmSetColorizationParameters.

#Include <WinAPIEx.au3>

Global $dParams = _WinAPI_DwmGetColorizationParameters()  ; Returns the $tDWMCP struct.  (because im lazy)
Global $aParams[8][2] = [[7], _
        ['Color', 3640655872], _
        ['AfterGlow', 3640655872], _
        ['ColorBalance', 56], _
        ['AfterGlowBalance', 11], _
        ['BlurBalance', 33], _
        ['GlassReflectionIntensity', 50], _
        ['OpaqueBlend', 0]]


For $i = 1 To $aParams[0][0]
    DllStructSetData($dParams, $aParams[$i][0], $aParams[$i][1])
Next

_WinAPI_DwmSetColorizationParameters($dParams)

Keep in mind that _WinAPI_DwmSetColorizationParameters makes system wide changes.

Link to comment
Share on other sites

  • Solution

Try this:
 

;coded by UEZ 2013

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

Global Const $SC_DRAGMOVE = 0xF012
Global $iW = 300, $iH = 200
_GDIPlus_Startup()

Global $hBitmap = _GDIPlus_CreateCurvedTranslucentPanel(0xE04576B2, 0x509FBADC, $iW, $iH)
;create GUI
Global $hGUI = GUICreate("", $iW, $iH, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
GUISetState()

SetTransparentBitmap($hGUI, $hBitmap)

GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
Until False

GUIDelete($hGUI)

_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()
Exit

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

Func _GDIPlus_CreateCurvedTranslucentPanel($iColorBG, $iColorFrame, $iW, $iH, $iRadiusCorner = 20) ;coded by UEZ 2013
    Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", $GDIP_PXF32ARGB, "ptr", 0, "int*", 0)
    $hBitmap = $hBitmap[6]
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2)

    DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hCtxt, "int", 7)

    Local $hPath = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    $hPath = $hPath[2]

    Local $hPath_Shape = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    $hPath_Shape = $hPath_Shape[2]

    Local $iPenSize = 2

    DllCall($ghGDIPDll, "uint", "GdipAddPathArc", "handle", $hPath, "float", $iW - ($iRadiusCorner * 2), "float", 0, "float", $iRadiusCorner * 2, "float", $iRadiusCorner * 2, "float", 270, "float", 90)
    DllCall($ghGDIPDll, "uint", "GdipAddPathArc", "handle", $hPath, "float", $iW - ($iRadiusCorner * 2), "float", $iH - ($iRadiusCorner * 2), "float", $iRadiusCorner * 2, "float", $iRadiusCorner * 2, "float", 0, "float", 90)
    DllCall($ghGDIPDll, "uint", "GdipAddPathArc", "handle", $hPath, "float", 0, "float", $iH - ($iRadiusCorner * 2), "float", $iRadiusCorner * 2, "float", $iRadiusCorner * 2, "float", 90, "float", 90)
    DllCall($ghGDIPDll, "uint", "GdipAddPathArc", "handle", $hPath, "float", 0, "float", 0, "float", $iRadiusCorner * 2, "float", $iRadiusCorner * 2, "float", 180, "float", 90)
    DllCall($ghGDIPDll, "uint", "GdipClosePathFigure", "handle", $hPath)

    Local $tPointF1 = DllStructCreate("float;float")
    Local $pPointF1 = DllStructGetPtr($tPointF1)
    Local $tPointF2 = DllStructCreate("float;float")
    Local $pPointF2 = DllStructGetPtr($tPointF2)

    DllStructSetData($tPointF1, 1, $iW / 2)
    DllStructSetData($tPointF1, 2, 0)
    DllStructSetData($tPointF2, 1, $iW / 2)
    DllStructSetData($tPointF2, 2, $iH)

    Local $iColorBG2 = BitAND(0xFF000000, $iColorBG) + BitAND(0x00FF0000, $iColorBG) - 0x200000 + BitAND(0x0000FF00, $iColorBG) - 0x2000 + BitAND(0x000000FF, $iColorBG) - 0x20
    Local $hBrush_Bg = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", $pPointF1, "ptr", $pPointF2, "uint", $iColorBG2, "uint", $iColorBG, "int", 1, "int*", 0)
    $hBrush_Bg = $hBrush_Bg[6]
    DllCall($ghGDIPDll, "uint", "GdipFillPath", "handle", $hCtxt, "handle", $hBrush_Bg, "handle", $hPath)

    DllStructSetData($tPointF1, 1, $iW / 2)
    DllStructSetData($tPointF1, 2, $iH / 5 + 7)
    DllStructSetData($tPointF2, 1, $iW / 2)
    DllStructSetData($tPointF2, 2, 0)

    Local $hBrush_Shape = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", $pPointF1, "ptr", $pPointF2, "uint", $iColorFrame, "uint", 0xA0FFFFFF, "int", 1, "int*", 0)
    $hBrush_Shape = $hBrush_Shape[6]

    DllCall($ghGDIPDll, "uint", "GdipAddPathArc", "handle", $hPath_Shape, "float", 0, "float", 0, "float", $iRadiusCorner * 2, "float", $iRadiusCorner * 2, "float", 180, "float", 90)
    DllCall($ghGDIPDll, "uint", "GdipAddPathArc", "handle", $hPath_Shape, "float", $iW - ($iRadiusCorner * 2), "float", 0, "float", $iRadiusCorner * 2, "float", $iRadiusCorner * 2, "float", 270, "float", 90)

    DllCall($ghGDIPDll, "uint", "GdipAddPathLine", "handle", $hPath_Shape, "float", 0, "float", $iRadiusCorner, "float", 0, "float", $iH / 5)
    DllCall($ghGDIPDll, "uint", "GdipAddPathLine", "handle", $hPath_Shape, "float", 0, "float", $iH / 5, "float", $iW / 2, "float", $iH / 5 + 7)
    DllCall($ghGDIPDll, "uint", "GdipAddPathLine", "handle", $hPath_Shape, "float", $iW, "float", $iH / 5, "float", $iW, "float", $iRadiusCorner)
    DllCall($ghGDIPDll, "uint", "GdipClosePathFigure", "handle", $hPath_Shape)

    DllCall($ghGDIPDll, "uint", "GdipFillPath", "handle", $hCtxt, "handle", $hBrush_Shape, "handle", $hPath_Shape)

    Local $hPen = _GDIPlus_PenCreate(0xF0000000 + $iColorFrame, $iPenSize)
    DllCall($ghGDIPDll, "uint", "GdipDrawPath", "handle", $hCtxt, "handle", $hPen, "handle", $hPath)

    DllCall($ghGDIPDll, "uint", "GdipDeletePath", "handle", $hPath)
    DllCall($ghGDIPDll, "uint", "GdipDeletePath", "handle", $hPath_Shape)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush_Bg)
    _GDIPlus_BrushDispose($hBrush_Shape)
    _GDIPlus_GraphicsDispose($hCtxt)
    Return $hBitmap
EndFunc

Func SetTransparentBitmap($hGUI, $hImage, $iOpacity = 0xFF)
    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,  $hMemDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>SetTransparentBitmap

 


Br,
UEZ

Edited by UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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...