Jump to content
Sign in to follow this  
James

Real Vista Aero Glass - Four functions

Recommended Posts

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

I highly doubt that Microsoft will include a ready function for drawing text. If they were going to do so, they either would have done it in a Vista SP or have it built into 7.

Still, if they add it, I'm not complaining, I just don't think they will.

Share this post


Link to post
Share on other sites

Other than using GDIPlus (which renders text horribly) or a png image of text, there is currently no way to show black text on top of glass. Is this correct? Is it possible with a label or using the Glass Area function? Yes, I have read the entire thread. I simply want to confirm this. Thanks!

Edited by intime69

Developer and Co-OwnerInTime Applicaitons Inc.

Share this post


Link to post
Share on other sites

Other than using GDIPlus (which renders text horribly) or a png image of text, there is currently no way to show black text on top of glass. Is this correct? Is it possible with a label or using the Glass Area function? Yes, I have read the entire thread. I simply want to confirm this. Thanks!

Everything has to be drawn with custom functions.

What about DrawThemeText??

Correct answer I believe.

Share this post


Link to post
Share on other sites

Everything has to be drawn with custom functions.

Correct answer I believe.

Thanks for the replies guys! And getting black text that actually looks like regular text with custom functions is nearly impossible. Right?

If anybody has an example of black text that looks like real text in front of glass, please post it here or let us know how you've succeeded. Thanks!

Edited by intime69

Developer and Co-OwnerInTime Applicaitons Inc.

Share this post


Link to post
Share on other sites

This works. Custom button drawn using code from AutoIt.De forum.

#include-once

#include <Constants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

OnAutoItExitRegister("AppExit")

Global Const $DWM_BB_ENABLE = 0x00000001

$Struct = DllStructCreate("int cxLeftWidth;int cxRightWidth;int cyTopHeight;int cyBottomHeight;")
$sStruct = DllStructCreate("dword;int;ptr;int")
; --- $DRAWITEMSTRUCT
Global Const $DRAWITEMSTRUCT = _
        'uint CtlType;' & _
        'uint CtlID;' & _
        'uint itemID;' & _
        'uint itemAction;' & _
        'uint itemState;' & _
        'hwnd hwndItem;' & _
        'ptr hDC;' & _
        'long rcItem[4];' & _
        'ulong_ptr itemData;'

Global Enum $PBS_NORMAL = 1, _
        $PBS_HOT, _
        $PBS_PRESSED, _
        $PBS_DISABLED, _
        $PBS_DEFAULTED, _
        $PBS_DEFAULTED_ANIMATING

Global Const $BP_PUSHBUTTON = 1

Global $g_hTheme
Global $g_hThemeLib

Global $g_hButtonProc
Global $g_bMouseHover = False

Global $ID_BUTTON_0
Global $ID_BUTTON_1


;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

$g_hThemeLib = DllOpen("uxtheme.dll")
If ($g_hThemeLib == -1) Then
    ConsoleWrite("! g_hThemeLib = " & $g_hThemeLib & @CRLF)
Else
    MainDlg()
EndIf

Exit (0)


Func MainDlg()

    Local $hWnd
    Local $hwndButton_1
    Local $MyArea[4] = [0, 0, 0, 45]

    $hWnd = GUICreate("Themed Ownerdraw Demo", 400, 300)

    $ID_BUTTON_1 = GUICtrlCreateButton("Custom button, not affected by Aero!", 25, 85, 350, 90)
    $ID_BUTTON_0 = GUICtrlCreateButton("Enable/Disable Aero", 25, 185, 350, 90)

    GUICtrlSetStyle($ID_BUTTON_1, BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW))

    $hwndButton_1 = GUICtrlGetHandle($ID_BUTTON_1)
    $g_hTheme = OpenThemeData($hwndButton_1, "Button")

;~  $g_hButtonProc = DllCallbackRegister ("ButtonWndProc", "long", "hwnd;uint;long;long")

    GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
;~  GUIRegisterMsg ($WM_MOUSEMOVE, "WM_MOUSEMOVE")

    GUISetState(5, $hWnd)

    While True

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $ID_BUTTON_0
                _DWM_Aero_EnableBlurBehind($hWnd)
        EndSwitch
    WEnd

EndFunc   ;==>MainDlg

Func WM_DRAWITEM($hWnd, $message, $wParam, $lParam)

    Local Const $ODA_DRAWENTIRE = 0x0001
    Local Const $ODA_SELECT = 0x0002
    Local Const $ODA_FOCUS = 0x0004
    Local Const $ODS_SELECTED = 0x0001
    Local Const $ODS_GRAYED = 0x0002
    Local Const $ODS_DISABLED = 0x0004
    Local Const $ODS_CHECKED = 0x0008
    Local Const $ODS_FOCUS = 0x0010
    Local Const $ODS_HOTLIGHT = 0x0040
    Local Const $ODS_INACTIVE = 0x0080
    Local Const $ODS_NOACCEL = 0x0100
    Local Const $ODS_NOFOCUSRECT = 0x0200

    Local $dis = DllStructCreate($DRAWITEMSTRUCT, $lParam)
    Local $hDC = DllStructGetData($dis, "hDC")
    Local $hwndItem = DllStructGetData($dis, "hwndItem")
    Local $nItemAction = DllStructGetData($dis, "itemAction")
    Local $nItemState = DllStructGetData($dis, "itemState")

    Local $lprcItem = DllStructGetPtr($dis, 8)

    Local $bChecked = BitAND($nItemState, $ODS_CHECKED)
    Local $bFocused = BitAND($nItemState, $ODS_FOCUS)
    Local $bGrayed = BitAND($nItemState, BitOR($ODS_GRAYED, $ODS_DISABLED))
    Local $bSelected = BitAND($nItemState, $ODS_SELECTED)

    Local $sFormat = "> WM_DRAWITEM (%#x, %d, %#x, %#x)"

    ConsoleWrite(StringFormat($sFormat, $hWnd, $message, $wParam, $lParam) & @CRLF)
    ConsoleWrite("> CtlType = " & DllStructGetData($dis, 1) & @CRLF)
    ConsoleWrite("> CtlID       = " & DllStructGetData($dis, 2) & @CRLF)
    ConsoleWrite("> itemID  = " & DllStructGetData($dis, 3) & @CRLF)
    ConsoleWrite("> itemAction  = " & DllStructGetData($dis, 4) & @CRLF)
    ConsoleWrite("> itemState   = " & Ptr(DllStructGetData($dis, 5)) & @CRLF)
    ConsoleWrite("> hwndItem    = " & DllStructGetData($dis, 6) & @CRLF)
    ConsoleWrite("> hDC     = " & DllStructGetData($dis, 7) & @CRLF)
    ConsoleWrite("> rcItem.left = " & DllStructGetData($dis, 8, 1) & @CRLF)
    ConsoleWrite("> rcItem.top  = " & DllStructGetData($dis, 8, 2) & @CRLF)
    ConsoleWrite("> rcItem.right    = " & DllStructGetData($dis, 8, 3) & @CRLF)
    ConsoleWrite("> rcItem.bottom   = " & DllStructGetData($dis, 8, 4) & @CRLF)
    ConsoleWrite("> itemData    = " & DllStructGetData($dis, 9) & @CRLF)

    ConsoleWrite("--------------------" & @CRLF)

    If ($nItemAction == $ODA_DRAWENTIRE) Then

        If ($bFocused) Then
            If ($bSelected) Then
                DrawControlTheme($hDC, $lprcItem, $hwndItem, $g_hTheme, $PBS_PRESSED)
            Else
                DrawControlTheme($hDC, $lprcItem, $hwndItem, $g_hTheme, $PBS_DEFAULTED)
            EndIf
            InflateRect($lprcItem, -3, -3)
            DrawFocusRect($hDC, $lprcItem)
        Else
            DrawControlTheme($hDC, $lprcItem, $hwndItem, $g_hTheme, $PBS_NORMAL)
        EndIf

    ElseIf ($nItemAction == $ODA_FOCUS) Then

        If ($bFocused) Then
            DrawControlTheme($hDC, $lprcItem, $hwndItem, $g_hTheme, $PBS_DEFAULTED)
        EndIf
        If ($bSelected) Then
            DrawControlTheme($hDC, $lprcItem, $hwndItem, $g_hTheme, $PBS_PRESSED)
        EndIf
        InflateRect($lprcItem, -3, -3)
        DrawFocusRect($hDC, $lprcItem)
    EndIf

    Return 1

EndFunc   ;==>WM_DRAWITEM

Func WM_MOUSEMOVE($hWnd, $message, $wParam, $lParam)



EndFunc   ;==>WM_MOUSEMOVE

Func AppExit()

    If ($g_hThemeLib) Then
        If ($g_hTheme) Then
            CloseThemeData($g_hTheme)
        EndIf
        DllClose($g_hThemeLib)
    EndIf

    If ($g_hButtonProc) Then
        DllCallbackFree($g_hButtonProc)
    EndIf

EndFunc   ;==>AppExit
;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««


Func DrawControlTheme($hDC, $lprect, $hwndButton, $hTheme, $iState)

    Local $rc = DllStructCreate("long;long;long;long", $lprect)
    Local $rcContent = DllStructCreate("long;long;long;long")
    Local $szButtonText
    Local $hr
    Local $cch

    $szButtonText = WinGetTitle($hwndButton)
    $cch = StringLen($szButtonText)

    If ($hTheme) Then

        $hr = DrawThemeBackground($hTheme, $hDC, $BP_PUSHBUTTON, _
                $iState, DllStructGetPtr($rc), 0)

        $hr = GetThemeBackgroundContentRect($hTheme, $hDC, _
                $BP_PUSHBUTTON, $iState, DllStructGetPtr($rc), DllStructGetPtr($rcContent))

        $hr = DrawThemeText($hTheme, $hDC, $BP_PUSHBUTTON, $iState, _
                $szButtonText, $cch, _
                BitOR($DT_CENTER, $DT_VCENTER, $DT_SINGLELINE), _
                0, DllStructGetPtr($rcContent))

    EndIf

EndFunc   ;==>DrawControlTheme

;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

Func InflateRect($lprc, $dx, $dy)

    Local $aRes = DllCall('user32.dll', 'int', 'InflateRect', _
            'ptr', $lprc, _  ; rectangle
            'int', $dx, _       ; amount to adjust width
            'int', $dy) ; amount to adjust height
    If @error Then _
            Return @error

    Return $aRes[0]

EndFunc   ;==>InflateRect

Func InvalidateRect($hWnd, $lprect, $bErase)

    Local $aRes = DllCall('user32.dll', 'int', 'InvalidateRect', _
            'hwnd', $hWnd, _           ; handle to window
            'ptr', $lprect, _  ; rectangle coordinates
            'int', $bErase) ; erase state
    If @error Then _
            Return @error

    Return $aRes[0]

EndFunc   ;==>InvalidateRect

Func DrawFocusRect($hDC, $lprc)

    Local $aRes = DllCall('user32.dll', 'int', 'DrawFocusRect', _
            'ptr', $hDC, _          ; handle to device context
            'ptr', $lprc) ; logical coordinates
    If @error Then _
            Return @error

    Return $aRes[0]

EndFunc   ;==>DrawFocusRect

;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

Func CloseThemeData($hTheme)

    Local $aRes = DllCall($g_hThemeLib, 'long', 'CloseThemeData', _
            'ptr', $hTheme)
    If @error Then _
            Return @error

    Return $aRes[0]

EndFunc   ;==>CloseThemeData

Func OpenThemeData($hWnd, $pszClassList)

    Local $aRes = DllCall($g_hThemeLib, 'ptr', 'OpenThemeData', _
            'hwnd', $hWnd, _
            'wstr', $pszClassList)
    If @error Then _
            Return @error

    Return $aRes[0]

EndFunc   ;==>OpenThemeData

Func DrawThemeBackground($hTheme, $hDC, $iPartId, $iStateId, $pRect, $pClipRect)

    Local $aRes = DllCall($g_hThemeLib, 'long', 'DrawThemeBackground', _
            'ptr', $hTheme, _
            'ptr', $hDC, _
            'int', $iPartId, _
            'int', $iStateId, _
            'ptr', $pRect, _
            'ptr', $pClipRect)
    If @error Then _
            Return @error

    Return $aRes[0]

EndFunc   ;==>DrawThemeBackground

Func DrawThemeEdge($hTheme, $hDC, $iPartId, $iStateId, $pDestRect, $uEdge, $uFlags, $pContentRect)

    Local $aRes = DllCall($g_hThemeLib, 'long', 'DrawThemeEdge', _
            'ptr', $hTheme, _
            'ptr', $hDC, _
            'int', $iPartId, _
            'int', $iStateId, _
            'ptr', $pDestRect, _
            'uint', $uEdge, _
            'uint', $uFlags, _
            'ptr', $pContentRect)
    If @error Then _
            Return @error

    Return $aRes[0]

EndFunc   ;==>DrawThemeEdge

Func DrawThemeText($hTheme, $hDC, $iPartId, $iStateId, $pszText, $iCharCount, $dwTextFlags, $dwTextFlags2, $pRect)

    Local $aRes = DllCall($g_hThemeLib, 'long', 'DrawThemeText', _
            'ptr', $hTheme, _
            'ptr', $hDC, _
            'int', $iPartId, _
            'int', $iStateId, _
            'wstr', $pszText, _
            'int', $iCharCount, _
            'dword', $dwTextFlags, _
            'dword', $dwTextFlags2, _
            'ptr', $pRect)
    If @error Then _
            Return @error

    Return $aRes[0]

EndFunc   ;==>DrawThemeText

Func GetThemeBackgroundContentRect($hTheme, $hDC, $iPartId, $iStateId, $pBoundingRect, $pContentRect)

    Local $aRes = DllCall($g_hThemeLib, 'long', 'GetThemeBackgroundContentRect', _
            'ptr', $hTheme, _
            'ptr', $hDC, _
            'int', $iPartId, _
            'int', $iStateId, _
            'ptr', $pBoundingRect, _
            'ptr', $pContentRect)
    If @error Then _
            Return @error

    Return $aRes[0]

EndFunc   ;==>GetThemeBackgroundContentRect


;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

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

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_ICE

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   ;==>_IsWinAero

It's long and I have no intention of looking at it further for now :x

Enjoy.

Share this post


Link to post
Share on other sites

This works. Custom button drawn using code from AutoIt.De forum.

It's long and I have no intention of looking at it further for now :x

Enjoy.

Wow! All of that coding for one button! Incredible! Thank you for finding this... Do you think it would be possible to do something like this with an input field (ideally)? or a label if not possible with an input field? I'm doing a Embedded IE Web Browser and I need an input field at the top (for the address bar) and I want it to be on top of glass or surrounded by glass like it's the case in FireFox for example or Opera. I'm using the "Vista_ApplyGlassArea" function. I have the text displaying correctly in white with a transparent input background but would like the text in black with the input background in white. Currently it's very difficult to read the white text in front of a light wallpaper since the input field is transparent. I can use a red background but it doesn't look very good and the text is still white. I need the text to be in black in front of a white background - input field.

Ideas? Let me know if you think it would be possible,

Thanks,

Ian

Edited by intime69

Developer and Co-OwnerInTime Applicaitons Inc.

Share this post


Link to post
Share on other sites

this is pretty cool :)

Share this post


Link to post
Share on other sites

Wow! All of that coding for one button! Incredible! Thank you for finding this... Do you think it would be possible to do something like this with an input field (ideally)? or a label if not possible with an input field? I'm doing a Embedded IE Web Browser and I need an input field at the top (for the address bar) and I want it to be on top of glass or surrounded by glass like it's the case in FireFox for example or Opera. I'm using the "Vista_ApplyGlassArea" function. I have the text displaying correctly in white with a transparent input background but would like the text in black with the input background in white. Currently it's very difficult to read the white text in front of a light wallpaper since the input field is transparent. I can use a red background but it doesn't look very good and the text is still white. I need the text to be in black in front of a white background - input field.

Ian,

I'm not actually sure how this would work for an input field. The idea of the background of the field is to contrast the text. If you have a glass input, how do you know the text will be visible?

Oh I see.... You'd have to "layer" it with SetLayeredWindow or something to that affect I believe. This is one of the UX problems with Aero, how do you know that the text will always be visible? This is why things like Chrome and such use backgrounds around the content (tabs, address bar) to ensure that the content will contrast and become visible.

this is pretty cool :)

Thanks!

Share this post


Link to post
Share on other sites

How would i get this to work on Win7 (x64) ?, i saw DFPWare's post about deleting the loop, but i can't figure out how and with what to replace it with.

Edit

Got it to work eventually, the buttons still tend to show up weird tho

Edited by katoNkatoNK

Share this post


Link to post
Share on other sites

You can easily do this using WinApiEx

Posted Image

Uploaded with ImageShack.us

#Include <WinAPIEx.au3>
#Include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $hForm, $AlphaKey = 0xABABAB

$hForm = GUICreate('MyGUI', 400, 400, -1, -1, -1, $WS_EX_LAYERED)
GUISetBkColor($AlphaKey)
GUICtrlCreateInput('Simple Text', 20, 20, 360, 19)
GUICtrlCreateEdit('', 20, 47, 360, 200)
GUICtrlCreateButton('OK', 165, 370, 70, 23)
GUICtrlCreateLabel("Label1",25,250,150,50)
GUICtrlSetFont(-1,25,800)
GUICtrlCreateLabel("Label1+1",25,300,150,50)
GUICtrlSetFont(-1,25,800)
GUICtrlSetColor(-1,0x00ff00)

_WinAPI_SetLayeredWindowAttributes($hForm, $AlphaKey, 0, $LWA_COLORKEY)
_WinAPI_DwmExtendFrameIntoClientArea($hForm)

GUISetState()

Do
Until GUIGetMsg() = -3


[size="2"][font="Lucida Sans Unicode"][b][/b][/font][/size]

Share this post


Link to post
Share on other sites

Might want to update main code, this also works with Win 7, and throws a "You're not vista" error.

Why check for only Vista as the os? What's the problem with just using _Vista_ICE() to see if the glass style is available? Something like this:

#include <GUIConstants.au3>

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

 Global $MyArea[4] = [50, 50, 50, 50]

 $GUI = GUICreate("Windows Vista DWM", 243, 243)
 $Apply = GUICtrlCreateButton("Apply", 80, 104, 83, 25, 0)
 $ICE = GUICtrlCreateButton("DWM Check", 80, 134, 83, 25, 0)
 GUISetState()

 While 1
     $iMsg = GUIGetMsg()
     Switch $iMsg
         Case $GUI_EVENT_CLOSE
             Exit
         Case $Apply
        ;_Vista_ApplyGlass($GUI)
        ;_Vista_EnableBlurBehind($GUI)
             _Vista_EnableBlurBehind($GUI)
     EndSwitch
 WEnd

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_ApplyGlass
; Description ...: Applys glass effect to a window
; Syntax.........: _Vista_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 _Vista_ApplyGlass($hWnd, $bColor = 0x000000)
     If _Vista_ICE() = 0 Then
         MsgBox(16, "_Vista_ApplyGlass", "Windows Aero is not available or disabled!")
     Else
         GUISetBkColor($bColor); Must be here!
         $Ret = DllCall("dwmapi.dll", "long", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "long*", DllStructGetPtr($Struct))
         If @error Then
             Return 0
             SetError(1)
         Else
             Return $Ret
         EndIf
     EndIf
 EndFunc ;==>_Vista_ApplyGlass

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_ApplyGlassArea
; Description ...: Applys glass effect to a window area
; Syntax.........: _Vista_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 _Vista_ApplyGlassArea($hWnd, $Area, $bColor = 0x000000)
     If _Vista_ICE() = 0 Then
         MsgBox(16, "_Vista_ApplyGlass", "Windows Aero is not available or disabled!")
     Else
         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
                 Return 0
             Else
                 Return $Ret
             EndIf
         Else
             MsgBox(16, "_Vista_ApplyGlassArea", "Area specified is not an array!")
         EndIf
     EndIf
 EndFunc ;==>_Vista_ApplyGlassArea

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_EnableBlurBehind
; Description ...: Enables the blur effect on the provided window handle.
; Syntax.........: _Vista_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 _Vista_EnableBlurBehind($hWnd, $bColor = 0x000000)
     If _Vista_ICE() = 0 Then
         MsgBox(16, "_Vista_ApplyGlass", "Windows Aero is not available or disabled!")
     Else
         Const $DWM_BB_ENABLE = 0x00000001

         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
             Return 0
         Else
             Return $Ret
         EndIf
     EndIf
 EndFunc ;==>_Vista_EnableBlurBehind

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_ICE
; Description ...: Returns 1 if DWM is enabled or 0 if not
; Syntax.........: _Vista_ICE()
; Parameters ....:
; Return values .: Success - Returns 1
;                 Failure - Returns 0
; Author ........: James Brooks
; Modified.......:
; Remarks .......: Thanks to BrettF
; Related .......:
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
 Func _Vista_ICE()
     $ICEStruct = DllStructCreate("int;")
     $Ret = DllCall("dwmapi.dll", "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($ICEStruct))
     If @error Then
         Return 0
     Else
         Return DllStructGetData($ICEStruct, 1)
     EndIf
 EndFunc ;==>_Vista_ICE

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites

Ok, make sense

I like this UDF. Had a bit of fun with it...

#include <GUIConstants.au3>
;~ #include <>

HotKeySet("{esc}","foo")

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

Global $MyArea[4] = [50, 50, 50, 50], $num = 0, $string = "|"
Global $aGui[Ceiling(@desktopwidth/100)+1][Ceiling(@DesktopHeight/100)+1]

Send("#d")

For $x = 1 to Ceiling(@desktopwidth/100)
For $y = 1 to Ceiling(@DesktopHeight/100)
    $string &= $x&","&$y&"|"
Next
Next

While $string <> "|"
    $a = StringSplit($string,"|")
    ConsoleWrite($a[0]-1&@CRLF)
    $s = $a[Random(2,$a[0]-1,1)]
    If $a[0]-1 = 2 Then $s = $a[2]
    $a2 = stringsplit($s,",")
    add($a2[1],$a2[2])
    $string = StringReplace($string,"|"&$a2[1]&","&$a2[2]&"|","|")
;~  sleep(100)
WEnd

While 1
    sleep(100)
WEnd

Func add($x,$y)
;~  ConsoleWrite($x&","&$y&@CRLF)
    $num += 1
    $color = "0x"&_PixelAvg(($x-1)*100+50, ($y-1)*100+50, 50, 20)
    $aGui[$x][$y] = GUICreate("", 100, 100, ($x-1)*100, ($y-1)*100, 0x80000000)
    _Vista_EnableBlurBehind($aGui[$x][$y],$color)
;~  _Vista_ApplyGlass($aGui[$x][$y],$color)
    GUISetState()
EndFunc

Func sub($x,$y)
    $num -= 1
    GUIDelete($aGui[$x][$y])
    $aGui[$x][$y] = 0
EndFunc

Func foo()
    Exit
EndFunc

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_ApplyGlass
; Description ...: Applys glass effect to a window
; Syntax.........: _Vista_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 _Vista_ApplyGlass($hWnd, $bColor = 0x000000)
     If _Vista_ICE() = 0 Then
         MsgBox(16, "_Vista_ApplyGlass", "Windows Aero is not available or disabled!")
     Else
         GUISetBkColor($bColor); Must be here!
         $Ret = DllCall("dwmapi.dll", "long", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "long*", DllStructGetPtr($Struct))
         If @error Then
             Return 0
             SetError(1)
         Else
             Return $Ret
         EndIf
     EndIf
 EndFunc ;==>_Vista_ApplyGlass

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_ApplyGlassArea
; Description ...: Applys glass effect to a window area
; Syntax.........: _Vista_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 _Vista_ApplyGlassArea($hWnd, $Area, $bColor = 0x000000)
     If _Vista_ICE() = 0 Then
         MsgBox(16, "_Vista_ApplyGlass", "Windows Aero is not available or disabled!")
     Else
         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
                 Return 0
             Else
                 Return $Ret
             EndIf
         Else
             MsgBox(16, "_Vista_ApplyGlassArea", "Area specified is not an array!")
         EndIf
     EndIf
 EndFunc ;==>_Vista_ApplyGlassArea

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_EnableBlurBehind
; Description ...: Enables the blur effect on the provided window handle.
; Syntax.........: _Vista_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 _Vista_EnableBlurBehind($hWnd, $bColor = 0x000000)
     If _Vista_ICE() = 0 Then
         MsgBox(16, "_Vista_ApplyGlass", "Windows Aero is not available or disabled!")
     Else
         Const $DWM_BB_ENABLE = 0x00000001

         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
             Return 0
         Else
             Return $Ret
         EndIf
     EndIf
 EndFunc ;==>_Vista_EnableBlurBehind

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_ICE
; Description ...: Returns 1 if DWM is enabled or 0 if not
; Syntax.........: _Vista_ICE()
; Parameters ....:
; Return values .: Success - Returns 1
;                 Failure - Returns 0
; Author ........: James Brooks
; Modified.......:
; Remarks .......: Thanks to BrettF
; Related .......:
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
 Func _Vista_ICE()
     $ICEStruct = DllStructCreate("int;")
     $Ret = DllCall("dwmapi.dll", "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($ICEStruct))
     If @error Then
         Return 0
     Else
         Return DllStructGetData($ICEStruct, 1)
     EndIf
 EndFunc ;==>_Vista_ICE

 Func _PixelAvg($x, $y, $range = 3, $step = 1)
    Local $r, $row, $col, $color, $avgR = 0, $avgG = 0, $avgB = 0
    If $range/2 = Round($range/2) Then $range += 1
    $r = Round(($range-1)/2,0)
    $total = 0
    For $col = -$r To $r step $step
        For $row = -$r+$col To $r+$col step $step
            $total += 1
            $color = PixelGetColor($x + $col, $y + $row)
            If $color = -1 Then Return SetError(1, 0, 0)
            $avgR += BitShift(BitAND($color, 0xFF0000), 16)
            $avgG += BitShift(BitAND($color, 0x00FF00), 8)
            $avgB += BitAND($color, 0xFF)
        Next
    Next
    $avgR = Round($avgR / $total)
    $avgG = Round($avgG / $total)
    $avgB = Round($avgB / $total)
    $color = hex(($avgR * 256 * 256) + ($avgG * 256) + $avgB,6)
;~  ConsoleWrite($total&@CRLF&hex(PixelGetColor($x, $y),6)&@CRLF&$color&@CRLF&@CRLF)
    Return $color
EndFunc   ;==>_PixelAvg

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites

You can easily do this using WinApiEx

This is nice as far as it goes. The fly in the ointment is radio buttons. The dark default text is not visible over a dark background. So then you are forced to use a button sized just large enough to contain the circle and add a label to the right. In that case I see no easy way to set the background color for the radio button dots and labels to match if the user sets the desktop color transparency option.

The closest I've been able to get it is by using a pixie tool to get the current transparency color and use it as an .ini file setting. Otherwise the places where I use labels for white text look blotchy.

Here's a a screen shot:

Posted Image

I tried using PixelGetColor() to get the matching color from inside my program. Didn't work. I had to use Pixie to get the hex code of the pixel under the mouse.

Edited by MilesAhead

Share this post


Link to post
Share on other sites

Is there anyway this would work with Vista Home Basic?

I know Basic does not have the Area but it has a slight glass effect.

I have seen some comments that it doesn't work, but think it will?


My ickle pieces of software :3Radio Scriptr //Almost completeSimple IP/URL pinger, my first program. //CompletedSimple Downloader // Working - basic stateOn-GoingRadio Scriptr - Radio Server.

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...