The reference to SetParent, the On Error Resume Next and the Exit Sub are all redundant + you can put it all on a couple of lines.
lAlpha: 0 is transparent, 255 is solid, anything inbetween is a grade of translucency. This will only work with top level windows on 2000 and above. See
http://www.vbforums.com/showthread.php?t=396385 for transparent form, but visible controls.
VB Code:
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
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 Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2
Private Sub SetTrans(ByVal lhWnd As Long, ByVal lAlpha As Byte)
SetWindowLong lhWnd, GWL_EXSTYLE, GetWindowLong(lhWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
SetLayeredWindowAttributes lhWnd, 0&, lAlpha, LWA_ALPHA
End Sub