VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "cCtrlClient"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private Const BITSPIXEL         As Long = 12

Private Const WS_MAXIMIZEBOX    As Long = &H10000
Private Const WS_MINIMIZEBOX    As Long = &H20000
Private Const WS_THICKFRAME     As Long = &H40000
Private Const WS_CAPTION        As Long = &HC00000

Private Const GWL_EXSTYLE       As Long = -20
Private Const GWL_STYLE         As Long = -16

Private Const WS_EX_LAYERED     As Long = &H80000

Private Const LWA_COLORKEY      As Long = &H1

Private Type tOSVERSIONINFO
    dwOSVersionInfoSize         As Long
    dwMajorVersion              As Long
    dwMinorVersion              As Long
    dwBuildNumber               As Long
    dwPlatformId                As Long
    szCSDVersion                As String * 128
End Type

Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As tOSVERSIONINFO) As Long
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32.dll" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function IsWindow Lib "user32" (ByVal hWnd As Long) As Long

Private c_lhWnd  As Long

Public Property Let Client(ByVal hWnd As Long)
    If Not IsWindow(hWnd) = 0 Then
        c_lhWnd = hWnd
    End If
End Property

Friend Function hWnd() As Long
    hWnd = c_lhWnd
End Function

Public Function ApplyStyle(Optional ByVal lColorKey As Long = vbMagenta) As Boolean
    Dim lRet As Long
    
    If Not c_lhWnd = 0 Then
        If IsLayeredSupported Then
            lRet = GetWindowLong(c_lhWnd, GWL_STYLE)
            lRet = lRet And Not WS_MAXIMIZEBOX And Not WS_MINIMIZEBOX And Not WS_THICKFRAME And Not WS_CAPTION
            Call SetWindowLong(c_lhWnd, GWL_STYLE, lRet)
        
            lRet = GetWindowLong(c_lhWnd, GWL_EXSTYLE)
            Call SetWindowLong(c_lhWnd, GWL_EXSTYLE, lRet Or WS_EX_LAYERED)
            Call SetLayeredWindowAttributes(c_lhWnd, lColorKey, 0, LWA_COLORKEY)
            
            ApplyStyle = True
        End If
    End If
End Function

Private Function IsLayeredSupported() As Boolean
    Dim OSV As tOSVERSIONINFO
  
    With OSV
        .dwOSVersionInfoSize = Len(OSV)
        Call GetVersionEx(OSV)
        If .dwMajorVersion >= 5 Then
            IsLayeredSupported = (GetDeviceCaps(GetDC(0), BITSPIXEL) >= 16)
        End If
    End With
End Function
