Jump to content

DWM/Transparent Button?


Biatu
 Share

Recommended Posts

I don't think that the button is transparent rather filled with a gradient color or texture. Same with the background.

 

You can try something like this here:

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


_GDIPlus_Startup()
Global Const $hGUI = GUICreate("Colored Buttons using GDI+", 600, 300)
Local $y, $iHeight = 1
For $y = 0 To 300 Step $iHeight
    GUICtrlCreateLabel("", 0, $y, 600, $iHeight)
    GUICtrlSetBkColor(-1, 0xF0F060 + Int(Abs(Cos($y / 0x50) * 0x80)))
    GUICtrlSetState(-1, $GUI_DISABLE)
Next
Global Const $iBtn1 = GUICtrlCreateButton("Default", 125, 75, 150, 150)
GUICtrlSetFont(-1, 14.5, 400, 0, "Arial", 4)
Global Const $iBtn2 = GUICtrlCreateButton("", 325, 75, 150, 150, $BS_BITMAP)
Global Const $hBmp = _GDIPlus_BtnCtrlSetBgColorGradient($iBtn2, "Colored", 146, 146)
GUISetState()

Do
    Switch GUIGetMsg()
        Case $iBtn1
            MsgBox(0, "Test", "Default button has been pressed")
        Case $iBtn2
            MsgBox(0, "Test", "Colored button has been pressed")
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hBmp)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
    EndSwitch
Until False

Func _GDIPlus_BtnCtrlSetBgColorGradient($iBtn, $sText, $iW, $iH, $iX1 = $iW / 2, $iY1 = 0, $iX2 = $iW / 2, $iY2 = $iH - $iH / 2, $iStartColor = 0xF0FFFFF0, $iEndColor = 0x4040FF40, $sFontSize = 14, $sFont = "Arial", $iFontColor = 0xFF000000) ;coded by UEZ build 2014-10-24
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGfx, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
    _GDIPlus_GraphicsSetTextRenderingHint($hGfx, 4)
    Local Const $hBrush_Bg = _GDIPlus_LineBrushCreate($iX1, $iY1, $iX2, $iY2, $iStartColor, $iEndColor, 1)
;~  _GDIPlus_LineBrushSetLinearBlend($hBrush_Bg, 0.15, 0.999)
    _GDIPlus_GraphicsFillRect($hGfx, 0, 0, $iW, $iH, $hBrush_Bg)
    Local $hBrush_Txt = _GDIPlus_BrushCreateSolid($iFontColor)
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $sFontSize)
    Local $hLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)
    Local $hStringFormat = _GDIPlus_StringFormatCreate()
    _GDIPlus_StringFormatSetAlign($hStringFormat, 1)
    _GDIPlus_StringFormatSetLineAlign($hStringFormat, 1)
    _GDIPlus_GraphicsDrawStringEx($hGfx, $sText, $hFont, $hLayout, $hStringFormat, $hBrush_Txt)
    Local Const $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($iBtn), $BM_SETIMAGE, $IMAGE_BITMAP, $hGDIBitmap))
    _GDIPlus_BrushDispose($hBrush_Bg)
    _GDIPlus_BrushDispose($hBrush_Txt)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_StringFormatDispose($hStringFormat)
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $hGDIBitmap
EndFunc   ;==>_GDIPlus_BtnCtrlSetBgColorGradient

 

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

Thanks UEZ, and James.

UEZ, as for non-transparency, i did a test and it is surely transparent.

Results:

output_pgLJVX.thumb.gif.3cf09e311b59b63c

And James, I had already looked through your DWM funcs, and the WinAPI one already included in autoit work fine.

Thank you Team

What is what? What is what.

Link to comment
Share on other sites

Indeed, you meant aero glass. I couldn't see that in the screenshot you have provided. Btw. this effect is already included in the _WinAPI_* stuff!

Aero glass is not working for Win8/10.

 

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

Yes, I miss aero blur in 8/10, but thankfully i still use 7. :D

As for the _WinAPI_Func, is there one in partifular you couldpoint me to that would enable that kind of effect on controls? Like using different theme elements for buttons? Cause the aero theme has different styles of buttons in the msstyles file.

Thank you

What is what? What is what.

Link to comment
Share on other sites

  • 1 month later...

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