' Declaração de API's necessários
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
' Definição de constantes
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const ULW_COLORKEY = &H1
Private Const ULW_ALPHA = &H2
Private Const ULW_OPAQUE = &H4
Private Const WS_EX_LAYERED = &H80000
' Define o form como transparente
Public Sub FormTransparence(ByVal hwnd As Long, ByVal bAlpha As Integer)
Dim msg As Long
' Ignora possíveis erros
On Error Resume Next
' Caso o valor seja inferior a 255 e superior
' a 0 aplica uma nova transparência
If bAlpha > 0 Or bAlpha < 255 Then
msg = GetWindowLong(hwnd, GWL_EXSTYLE)
msg = msg Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, msg
SetLayeredWindowAttributes hwnd, 0, bAlpha, LWA_ALPHA
End If
End Sub
' Define o form com opaco
Public Sub MakeOpaque(ByVal hwnd As Long)
Dim msg As Long
' Ignora possíveis erros
On Error Resume Next
msg = GetWindowLong(hwnd, GWL_EXSTYLE)
msg = msg And Not WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, msg
SetLayeredWindowAttributes hwnd, 0, 0, LWA_ALPHA
End Sub[/code]
[b]Manera de Usarlo:[/b]
Si Adicionas Botones:
[code]Private Sub cmdButtonTrans_Click()
FormTransparence Me.hwnd, 180
End Sub[/code]
[code]Private Sub cmdButtonNormal_Click()
FormTransparence Me.hwnd, 250
End Sub
Creditos: styleProfessionalCode