Source Code Transparent Form

Embed Size (px)

DESCRIPTION

VB6

Citation preview

Private Sub Check1_Click()If Check1.Value = 1 ThenMakeTransparent Me.hWnd, 100ElseIf Check1.Value = 0 ThenMakeOpaque Me.hWndEnd IfEnd SubModul :Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As LongPrivate Declare Function UpdateLayeredWindow Lib "user32" (ByVal hWnd As Long, ByVal hdcDst As Long, pptDst As Any, psize As Any, ByVal hdcSrc As Long, pptSrc As Any, crKey As Long, ByVal pblend As Long, ByVal dwFlags As Long) As LongPrivate Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Const GWL_EXSTYLE = (-20)Private Const LWA_COLORKEY = &H1Private Const LWA_ALPHA = &H2Private Const ULW_COLORKEY = &H1Private Const ULW_ALPHA = &H2Private Const ULW_OPAQUE = &H4Private Const WS_EX_LAYERED = &H80000Public Function isTransparent(ByVal hWnd As Long) As BooleanOn Error Resume NextDim Msg As LongMsg = GetWindowLong(hWnd, GWL_EXSTYLE)If (Msg And WS_EX_LAYERED) = WS_EX_LAYERED Then isTransparent = TrueElse isTransparent = FalseEnd IfIf Err Then isTransparent = FalseEnd IfEnd FunctionPublic Function MakeTransparent(ByVal hWnd As Long, Perc As Integer) As LongDim Msg As LongOn Error Resume NextIf Perc < 0 Or Perc > 255 Then MakeTransparent = 1Else Msg = GetWindowLong(hWnd, GWL_EXSTYLE) Msg = Msg Or WS_EX_LAYERED SetWindowLong hWnd, GWL_EXSTYLE, Msg SetLayeredWindowAttributes hWnd, 0, Perc, LWA_ALPHA MakeTransparent = 0End IfIf Err Then MakeTransparent = 2End IfEnd FunctionPublic Function MakeOpaque(ByVal hWnd As Long) As LongDim Msg As LongOn Error Resume NextMsg = GetWindowLong(hWnd, GWL_EXSTYLE)Msg = Msg And Not WS_EX_LAYEREDSetWindowLong hWnd, GWL_EXSTYLE, MsgSetLayeredWindowAttributes hWnd, 0, 0, LWA_ALPHAMakeOpaque = 0If Err Then MakeOpaque = 2End IfEnd Function