Jump to content

Real Vista Aero Glass - Four functions


James
 Share

Recommended Posts

You don't apply this to your controls directly, as the DWM functions I used "breaks" them. You need to apply this to the GUI itself. Take a look at the example I posted on the first page. ;)

If you want glass controls, you need to draw them yourself, something I haven't worked out yet.

Sorry about that James. I meant that I don't want it applied to my controls. It applies it to the whole GUI. I don't want the controls affected. Not quite sure how to make that work. I looked at the example but mine was still applied the entire GUI. Where is that it does not apply it to the controls?

Edited by EndFunc
EndFuncAutoIt is the shiznit. I love it.
Link to comment
Share on other sites

Sorry about that James. I meant that I don't want it applied to my controls. It applies it to the whole GUI. I don't want the controls affected. Not quite sure how to make that work. I looked at the example but mine was still applied the entire GUI. Where is that it does not apply it to the controls?

Apart from owner drawn controls (I don't stand a cats hell in chance of making those work), you could try using, _Vista_ApplyGlassArea function and using them around the controls.
Link to comment
Share on other sites

Perhaps it's not a groundbreaking information for all of you but I was surprised that the _Vista_ApplyGlass-Function applied on a $WS_POPUP-Form leads to a transparent Form where only the controls stay visible. I didn't know that nor do I know enough to explain it - But for me it comes in handy at the moment.

I'm already working with that additional "feature" since two weeks ;)

UTA

Link to comment
Share on other sites

Perhaps it's not a groundbreaking information for all of you but I was surprised that the _Vista_ApplyGlass-Function applied on a $WS_POPUP-Form leads to a transparent Form where only the controls stay visible. I didn't know that nor do I know enough to explain it - But for me it comes in handy at the moment.

I'm already working with that additional "feature" since two weeks ;)

UTA

Mind sharing an example of this please? Would be interesting to see this :evil:
Link to comment
Share on other sites

Just add this to the top of your functions:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

$Struct = DllStructCreate("int cxLeftWidth;int cxRightWidth;int cyTopHeight;int cyBottomHeight;")
$sStruct = DllStructCreate("dword;int;ptr;int")

$GUI = GUICreate("Windows Vista DWM", 243, 243, -1,-1, $WS_POPUP)
GUISetBkColor(0x0000CC) ; just for better visibility of the forms client area
$Icon = GUICtrlCreateIcon(@WindowsDir & "\explorer.exe",0, 10, 10, 32, 32)
$Apply = GUICtrlCreateButton("Apply", 80, 104, 83, 25, 0)
GUISetState()

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE, $Icon
            Exit
        Case $Apply
            If _Vista_ICE() Then
                _Vista_ApplyGlass($GUI, 0x000000)
            EndIf
    EndSwitch
WEnd

edit: ähm.. by the way - This works for Vista 32bit and Win 7 64bit for me. But I didn't test it on other OSs...

UTA

Edited by UTA
Link to comment
Share on other sites

So you should just be able to see the icon and button?

If so, it works on Windows 7 32bit.

Very weird behaviour!

Exactly! I'm sure it will work on Vista 64bit also, I just wanted to mention that I'm NOT sure what it will do on XP...

For me it's strange too, but very handy at the moment ;)

UTA

Link to comment
Share on other sites

  • 3 months later...

Is it possible to get Black Text on the Aero?

I just started another project after not messing with this Aero code for a few months, and I can't even remember if it's possible (With AutoIt anyway)...

P.S. Any un-posted updates lately? You were on a role there for a while Mr.James. :idea:

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

Is it possible to get Black Text on the Aero?

P.S. Any un-posted updates lately? You were on a role there for a while Mr.James. :idea:

Black text has to be drawn with GDI I do believe. Wait... If IIRC, white text is what we'd use as black normally.

Only some fixes to the code, I should really post them but I'm busy working :)

Edited by JamesBrooks
Link to comment
Share on other sites

I had forgot about GDI+! :idea:

Thanks James!

I tried white text, and that's exactly what it was... White. I'm probably doing something wrong, but GDI+ works just the same. I'll be watching for those updates, Thanks again. :)

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

It's bizarre. I drew a string on to the GUI using _GDIPlus_GraphicsDrawString() but it's instantly hidden when glass is enabled.

#include <GDIPlus.au3>
#include <GUIConstants.au3>

_GDIPlus_Startup ()

Global Const $DWM_BB_ENABLE = 0x00000001
Global $MyArea[4] = [0, 0, 0, 45]
$Struct = DllStructCreate("int cxLeftWidth;int cxRightWidth;int cyTopHeight;int cyBottomHeight;")
$sStruct = DllStructCreate("dword;int;ptr;int")

$hGUI = GUICreate("Windows Vista DWM", 243, 243)
;$Label = GUICtrlCreateLabel("Aero Test", 10, 10)
$Apply = GUICtrlCreateButton("Apply", 80, 104, 83, 25, 0)
$ICE = GUICtrlCreateButton("DWM Check", 80, 134, 83, 25, 0)
GUISetState()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
_GDIPlus_GraphicsDrawString ($hGraphic, "This is a test string on DWM.", 35, 20)

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_GraphicsDispose ($hGraphic)
            _GDIPlus_Shutdown ()
            Exit
        Case $Apply
            ;_DWM_Aero_ApplyGlass($hGUI)
            _DWM_Aero_EnableBlurBehind($hGUI)
            ;_DWM_Aero_ApplyGlassArea($hGUI, $MyArea, 0xE2E2E2)
            If Not @error Then
                GUICtrlSetColor($Apply, 0xFFFFFF)
                GUICtrlSetBkColor($Apply, 0x000000)
                GUICtrlSetColor($ICE, 0xFFFFFF)
                GUICtrlSetBkColor($ICE, 0x000000)
                ;GuiCtrlSetColor($Label, 0xFFFFFF)
            EndIf
        Case $ICE
            If _DWM_ICE() Then
                MsgBox(0, "_DWM_Aero_ICE", "DWM is enabled!")
            Else
                MsgBox(0, "_DWM_Aero_ICE", "DWM is NOT enabled!")
            EndIf
    EndSwitch
WEnd

; #FUNCTION#;===============================================================================
;
; Name...........: _DWM_Aero_ApplyGlass
; Description ...: Applys glass effect to a window
; Syntax.........: _DWM_Aero_ApplyGlass($hWnd, [$bColor)
; Parameters ....: $hWnd - Window handle:
;                  $bColor  - Background color
; Return values .: Success - No return
;                  Failure - Returns 0
; Author ........: James Brooks
; Modified.......:
; Remarks .......: Thanks to weaponx!
; Related .......:
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
Func _DWM_Aero_ApplyGlass($hWnd, $bColor = 0x000000)
    If Not _IsWinAero() Then
        SetError(0, 0, -1)
        Return 0
    Else
        GUISetBkColor($bColor); Must be here!
        $Ret = DllCall("dwmapi.dll", "long", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "long*", DllStructGetPtr($Struct))
        If @error Then
            SetError(0)
            Return 0
        Else
            Return $Ret
        EndIf
    EndIf
EndFunc   ;==>_DWM_Aero_ApplyGlass

; #FUNCTION#;===============================================================================
;
; Name...........: _DWM_Aero_ApplyGlassArea
; Description ...: Applys glass effect to a window area
; Syntax.........: _DWM_Aero_ApplyGlassArea($hWnd, $Area, [$bColor)
; Parameters ....: $hWnd - Window handle:
;                   $Area - Array containing area points
;                  $bColor  - Background color
; Return values .: Success - No return
;                  Failure - Returns 0
; Author ........: James Brooks
; Modified.......:
; Remarks .......: Thanks to monoceres!
; Related .......:
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
Func _DWM_Aero_ApplyGlassArea($hWnd, $Area, $bColor = 0x000000)
    If Not _IsWinAero() Then
        SetError(0, 0, -1)
        Return 0
    Else
        If _DWM_ICE() Then
            ConsoleWrite("ICE ENABLED!" & @CRLF)
            If IsArray($Area) Then
                DllStructSetData($Struct, "cxLeftWidth", $Area[0])
                DllStructSetData($Struct, "cxRightWidth", $Area[1])
                DllStructSetData($Struct, "cyTopHeight", $Area[2])
                DllStructSetData($Struct, "cyBottomHeight", $Area[3])
                GUISetBkColor($bColor); Must be here!
                $Ret = DllCall("dwmapi.dll", "long*", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "ptr", DllStructGetPtr($Struct))
                If @error Then
                    SetError(0, 0, 1)
                    Return 0
                Else
                    Return $Ret
                EndIf
            Else
                ConsoleWrite("ICE DISABLED!" & @CRLF)
                SetError(1)
                Return 0
            EndIf
        Else
            SetError(2, 0, 2)
            Return 0
        EndIf
    EndIf
EndFunc   ;==>_DWM_Aero_ApplyGlassArea

; #FUNCTION#;===============================================================================
;
; Name...........: _DWM_Aero_EnableBlurBehind
; Description ...: Enables the blur effect on the provided window handle.
; Syntax.........: _DWM_Aero_EnableBlurBehind($hWnd)
; Parameters ....: $hWnd - Window handle:
; Return values .: Success - No return
;                  Failure - Returns 0
; Author ........: James Brooks
; Modified.......:
; Remarks .......: Thanks to komalo
; Related .......:
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
Func _DWM_Aero_EnableBlurBehind($hWnd, $bColor = 0x000000)
    If Not _IsWinAero() Then
        SetError(0, 0, -1)
        Return 0
    Else
        DllStructSetData($sStruct, 1, $DWM_BB_ENABLE)
        DllStructSetData($sStruct, 2, "1")
        DllStructSetData($sStruct, 4, "1")

        GUISetBkColor($bColor); Must be here!
        $Ret = DllCall("dwmapi.dll", "int", "DwmEnableBlurBehindWindow", "hwnd", $hWnd, "ptr", DllStructGetPtr($sStruct))
        If @error Then
            SetError(0, 0, 1)
            Return 0
        Else
            Return $Ret
        EndIf
    EndIf
EndFunc   ;==>_DWM_Aero_EnableBlurBehind

; #FUNCTION#;===============================================================================
;
; Name...........: _DWM_ICE
; Description ...: Returns 1 if DWM is enabled or 0 if not
; Syntax.........: _DWM_ICE()
; Parameters ....:
; Return values .: Success - Returns 1
;                  Failure - Returns 0
; Author ........: James Brooks
; Example .......; Yes
;
;;==========================================================================================
Func _DWM_ICE()
    If Not _IsWinAero() Then
        $ICEStruct = DllStructCreate("int;")
        $Ret = DllCall("dwmapi.dll", "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($ICEStruct))
        If @error Then
            SetError(0, 0, -1) ; DWM is not active
            Return 0
        Else
            Return DllStructGetData($ICEStruct, 1)
        EndIf
    Else
        SetError(1, 0, 1) ; Not running Windows 6.1 or above
        Return 1
    EndIf
EndFunc   ;==>_DWM_Aero_ICE

; #FUNCTION#;===============================================================================
;
; Name...........: __GetVersionEx
; Description ...: Returns version number of OS
; Syntax.........: _GetVersionEx()
; Parameters ....:
; Return values .: Success - Returns version integer
;                  Failure - Returns 0
; Author ........: James Brooks
;
;;==========================================================================================
Func _IsWinAero()
    Local $__iVer = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion")
    If $__iVer >= 6.1 Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

I hate GDI.

Seems adding this might help.

Edited by JamesBrooks
Link to comment
Share on other sites

  • 6 months later...

:graduated: Sexy!

I'm glad you like the functions Firestorm, I'm sorry I can't get the glow to work, that would be darn right amazing!

Hello James. I was recently browsing the forums, and I found some code that might help you in your way to making text glow.

Working code

#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("MustDeclareVars", 1)

Global Const $DTT_GRAYED = 0x00000001
Global Const $DTT_FLAGS2VALIDBITS = $DTT_GRAYED
Global Const $DTT_TEXTCOLOR = 0x00000001
Global Const $DTT_BORDERCOLOR = 0x00000002
Global Const $DTT_SHADOWCOLOR = 0x00000004
Global Const $DTT_SHADOWTYPE = 0x00000008
Global Const $DTT_SHADOWOFFSET = 0x00000010
Global Const $DTT_BORDERSIZE = 0x00000020
Global Const $DTT_FONTPROP = 0x00000040
Global Const $DTT_COLORPROP = 0x00000080
Global Const $DTT_STATEID = 0x00000100
Global Const $DTT_CALCRECT = 0x00000200
Global Const $DTT_APPLYOVERLAY = 0x00000400
Global Const $DTT_GLOWSIZE = 0x00000800
Global Const $DTT_CALLBACK = 0x00001000
Global Const $DTT_COMPOSITED = 0x00002000
Global Const $DTT_VALIDBITS = BitOR($DTT_TEXTCOLOR, $DTT_BORDERCOLOR, $DTT_SHADOWCOLOR, $DTT_SHADOWTYPE, $DTT_SHADOWOFFSET, $DTT_BORDERSIZE, _
        $DTT_FONTPROP, $DTT_COLORPROP, $DTT_STATEID, $DTT_CALCRECT, $DTT_APPLYOVERLAY, $DTT_GLOWSIZE, $DTT_COMPOSITED)

If Not IsDeclared("WM_DWMCOMPOSITIonchangeD") Then Global Const $WM_DWMCOMPOSITIonchangeD = 0x031E
If Not IsDeclared("tagDTTOPTS") Then Global Const $tagDTTOPTS = _
"uint Size;uint Flags;uint clrText;uint clrBorder;uint clrShadow;int TextShadowType;" & $tagPOINT & _
";int BorderSize;int FontPropId;int ColorPropId;int StateId;int ApplyOverlay;int GlowSize;ptr DrawTextCallback;int lParam;"

Global $hGUI = GUICreate("Test", 300, 300)
Global $hTheme = _WinAPI_OpenThemeData($hGUI, "globals")

GUIRegisterMsg($WM_ERASEBKGND, "_WM_ERASEBKGND")
GUIRegisterMsg($WM_DWMCOMPOSITIonchangeD, "_WM_DWMCOMPOSITIonchangeD")
GUISetState()

_SendMessage($hGUI, $WM_DWMCOMPOSITIonchangeD)
AdlibRegister("_DrawTime", 1000)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_CloseThemeData($hTheme)
GUIDelete()
Exit


Func _DrawTime()
    Local $hDC = _WinAPI_GetDC($hGUI)
    Local $tClientRect = _WinAPI_GetClientRect($hGUI)
    Local $tST = _Date_Time_GetLocalTime()
    Local $sText = _Date_Time_SystemTimeToTimeStr($tST)

    _DrawGlowingText($hDC, $sText, $tClientRect, 10)

    _WinAPI_ReleaseDC($hGUI, $hDC)
EndFunc

Func _WM_ERASEBKGND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hDC = $iwParam
    Local $tClientRect = _WinAPI_GetClientRect($hWnd)
    Local $hBrush = _WinAPI_GetStockObject($BLACK_BRUSH)

    _WinAPI_FillRect($hDC, DllStructGetPtr($tClientRect), $hBrush)

    Return 1
EndFunc

Func _WM_DWMCOMPOSITIonchangeD($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tMargs = DllStructCreate($tagMARGINS)

    If _WinAPI_DwmIsCompositionEnabled() Then
        For $i = 1 To 4
            DllStructSetData($tMargs, $i, -1)
        Next
        _WinAPI_DwmExtendFrameIntoClientArea($hWnd, $tMargs)
    EndIf

    Return 0
EndFunc

Func _DrawGlowingText($hDC, $sText, $tRc, $iGlowSize)
    Local $hCDC
    Local $tRcText
    Local $tBI, $tDTO
    Local $hDIBBmp, $hOldBmp
    Local $tST

    $hCDC = _WinAPI_CreateCompatibleDC($hDC)

    $tBI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBI, "Size", DllStructGetSize($tBI)-4)
    DllStructSetData($tBI, "Width", DllStructGetData($tRc, "Right")-DllStructGetData($tRc, "Left"))
    DllStructSetData($tBI, "Height", -(DllStructGetData($tRc, "Bottom")-DllStructGetData($tRc, "Top")))
    DllStructSetData($tBI, "Planes", 1)
    DllStructSetData($tBI, "BitCount", 32)
    DllStructSetData($tBI, "Compression", 0) ; BI_RGB

    $hDIBBmp = _WinAPI_CreateDIBSection($hDC, $tBI)
    $hOldBmp = _WinAPI_SelectObject($hCDC, $hDIBBmp)

    $tDTO = DllStructCreate($tagDTTOPTS)
    DllStructSetData($tDTO, "Size", DllStructGetSize($tDTO))
    DllStructSetData($tDTO, "Flags", BitOR($DTT_GLOWSIZE, $DTT_COMPOSITED))
    DllStructSetData($tDTO, "GlowSize", $iGlowSize)

    _WinAPI_DrawThemeTextEx($hTheme, $hCDC, 0, 0, $sText, _
        BitOR($DT_SINGLELINE, $DT_CENTER, $DT_VCENTER, $DT_NOPREFIX), $tRc, $tDTO)

    _WinAPI_BitBlt($hDC, DllStructGetData($tRc, "Left"), DllStructGetData($tRc, "Top"), _
        DllStructGetData($tRc, "Right")-DllStructGetData($tRc, "Left"), _
        DllStructGetData($tRc, "Bottom")-DllStructGetData($tRc, "Top"), $hCDC, 0, 0, 0xCC0020) ; SRCCOPY

    _WinAPI_SelectObject($hCDC, $hOldBmp)
    _WinAPI_DeleteObject($hDIBBmp)
    _WinAPI_DeleteDC($hCDC)
EndFunc

Func _WinAPI_DwmExtendFrameIntoClientArea($hWnd, ByRef $tMargins)
    Local $aResult = DllCall("dwmapi.dll", "int", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "ptr", DllStructGetPtr($tMargins))

    If @error Then Return SetError(@error, @extended, -1)
    Return $aResult[0]
EndFunc

Func _WinAPI_DwmIsCompositionEnabled()
    Local $aResult = DllCall("dwmapi.dll", "int", "DwmIsCompositionEnabled", "int*", 0)

    If @error Then Return SetError(@error, @extended, -1)
    Return SetError($aResult[0], 0, $aResult[1])
EndFunc

Func _WinAPI_CreateDIBSection($hDC, Const ByRef $tBmpInfo, $iUsage = 0, $pBits = 0, $hSecond = 0, $iOffset = 0)
    Local $aResult = DllCall("gdi32.dll", "hwnd", "CreateDIBSection", "hwnd", $hDC, "ptr", DllStructGetPtr($tBmpInfo), _
                        "uint", $iUsage, "ptr", $pBits, "hwnd", $hSecond, "uint", $iOffset)

    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] = 87 Then Return SetError(1, 1, 0); 87 = ERROR_INVALID_PARAMETER
    If $aResult[0] = 0 Then Return SetError(1, 2, 0)
    Return SetError(0, 0, $aResult[0])
EndFunc

Func _WinAPI_DrawThemeTextEx($hTheme, $hDC, $iPartId, $iStateId, $sText, $iFlags, ByRef $tRect, Const ByRef $tDTTOPTS)
    Local $aResult = DllCall("uxtheme.dll", "int", "DrawThemeTextEx", "ptr", $hTheme, "hwnd", $hDC, "int", $iPartId, "int", $iStateId, _
                        "wstr", $sText, "int", -1, "uint", $iFlags, "ptr", DllStructGetPtr($tRect), "ptr", DllStructGetPtr($tDTTOPTS))

    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] <> 0 Then Return SetError(1, 0, 0)
    Return SetError(0, 0, $aResult[0] = 0)
EndFunc

Func _WinAPI_OpenThemeData($hWnd, $sClassList)
    Local $aResult = DllCall("uxtheme.dll", "hwnd", "OpenThemeData", "hwnd", $hWnd, "wstr", $sClassList)

    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] = 0 Then Return SetError(1, 0, 0)
    Return SetError(0, 0, $aResult[0])
EndFunc

Func _WinAPI_CloseThemeData($hTheme)
    Local $aResult = DllCall("uxtheme.dll", "int", "CloseThemeData", "hwnd", $hTheme)

    If @error Then Return SetError(@error, @extended, 0)
    Return SetError(0, 0, $aResult[0] = 0)
EndFunc

Credit:

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

Oddly, it won't let me edit my above post. So also check this post out:

Edited by Skrip

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

Thanks Skrip!

Looks like some pretty neat code, shame it's such a tedious task for something which is coupled with something relatively simple.

That's what I was thinking. I'm attempting to figure out an easier way to do this, but progress is slow and rather tedious.

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

That's what I was thinking. I'm attempting to figure out an easier way to do this, but progress is slow and rather tedious.

They really need to add some text drawing functions to the DWM functions. I see little changes here and there. Like in Vista if you do the Blur Behind command prompt, the thumb control on the scrollbar is washed out. But in Windows Seven it's drawn correctly. Also C# can draw text on buttons on glass that look normal. (But you still have to use GDI+ to draw a label on the glass.) Maybe in Windows Eight they'll be a UserDrawGlassText or something that won't take all this setup to use. Either that or they need to fix how all the Controls are drawn at the WinAPI level to accommodate glass. It's like drawing one label is more lines of code than the rest of the app for a small utility.

Link to comment
Share on other sites

They really need to add some text drawing functions to the DWM functions. I see little changes here and there. Like in Vista if you do the Blur Behind command prompt, the thumb control on the scrollbar is washed out. But in Windows Seven it's drawn correctly. Also C# can draw text on buttons on glass that look normal. (But you still have to use GDI+ to draw a label on the glass.) Maybe in Windows Eight they'll be a UserDrawGlassText or something that won't take all this setup to use. Either that or they need to fix how all the Controls are drawn at the WinAPI level to accommodate glass. It's like drawing one label is more lines of code than the rest of the app for a small utility.

I think Win 8 is shooting a little far. Win 7 SP1?

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

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