Sign in to follow this  
Followers 0
E1M1

Is there betterway to draw tabs on glass window?

4 posts in this topic

I am trying to design my own tabbed window. At the moment I would have to create arrays to show and hide right items based on tab clicks which is 1 of the problems but main problemquestion is that how do draw buttons? w/o black background? If i have no black background buttons text get replaced with transparent color.

$iTab is zerobased tab index.

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <array.au3>
#Include <GuiButton.au3>
Dim $tabs[1]
Dim $ctrls[1]
$hprev = -1
$iTab = -1
$Struct = DllStructCreate("int cxLeftWidth;int cxRightWidth;int cyTopHeight;int cyBottomHeight;")
$sStruct = DllStructCreate("dword;int;ptr;int")
Dim $Area[4] = [0, 0, 50, 0]

$GUI = GUICreate("Tabs", 800, 243)
;~ $Apply = GUICtrlCreateButton("Apply", 80, 104, 83, 25, 0)
$add = GUICtrlCreateButton("new",800-30, 0, 25, 25, BitOR($BS_ICON, $WS_GROUP))
GUICtrlSetImage(-1, "D:\My Documents\ikoon\lisa.ico", -1, 0)
$remove = GUICtrlCreateButton("del",800-60, 0, 25, 25, BitOR($BS_ICON, $WS_GROUP))
GUICtrlSetImage(-1, "D:\My Documents\ikoon\1298500642_edit_remove.ico", -1, 0)
GUISetState(@SW_SHOW, $GUI)
_Vista_ApplyGlassArea($GUI, $Area)

GUIRegisterMsg(0x0006, "ClickHandler")

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $add

            AddTab()
    EndSwitch
WEnd

Func ClickHandler($hWnd, $Msg, $wParam, $lParam)
    For $i = 1 To UBound($tabs) - 1
        If $hWnd = $tabs[$i -1] Then
            If $hprev <> $ctrls[$i -1] Then
            GUICtrlSetImage($hprev,"normal.bmp")
            GUICtrlSetImage($ctrls[$i -1],"active.bmp")
            $hprev = $ctrls[$i -1]
            $iTab = $i -1
            EndIf
        EndIf
    Next
EndFunc   ;==>ClickHandler

Func AddTab()
    $tabs[UBound($tabs) - 1] = GUICreate("", 100, 30, (UBound($tabs) - 1) * 100, 0, 0x80000000, 0x00000040, $GUI)
    GUISetBkColor(0, $tabs[UBound($tabs) - 1])
    $rgn1 = _WinAPI_CreateRoundRectRgn(0, 0, 101, 20, 7, 7) ; left-top
    $rgn2 = _WinAPI_CreateRectRgn(0, 10, 100, 20) ; right-top
    _WinAPI_CombineRgn($rgn1, $rgn1, $rgn2, $RGN_OR)
    _WinAPI_DeleteObject($rgn2)
    _WinAPI_SetWindowRgn($tabs[UBound($tabs) - 1], $rgn1)
    $ctrls[UBound($ctrls) - 1] = GUICtrlCreatePic("normal.bmp", 0, 0, 100, 20)
    ReDim $ctrls[UBound($ctrls) + 1]
    GUICtrlCreateLabel("Tab " & UBound($tabs), 5, 3, 90, 17)
    GUICtrlSetBkColor(-1, -2)
    GUISetState(@SW_SHOW, $tabs[UBound($tabs) - 1])
    ReDim $tabs[UBound($tabs) + 1]
EndFunc   ;==>AddTab

; #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 @OSVersion <> "WIN_VISTA" And @OSVersion <> "WIN_7" Then
        MsgBox(16, "_Vista_ApplyGlass", "You are not running Vista!")
        Exit
    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_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

edited

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

That's true. But then I would have to draw not only buttons but everything myself.

http://www.codeproject.com/KB/vista/textonglass.aspx

Some how it's possible.

solution: Create black image where you want to place glass.

Edited by E1M1

edited

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  
Followers 0