'参考地址:http://baike.baidu.com/view/1329156.htm
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
Const WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1
Private Sub Command1_Click() '将窗体中灰色的地方设为完全透明
SetWindowLong hwnd, GWL_EXSTYLE, WS_EX_LAYERED
SetLayeredWindowAttributes hwnd, RGB(236, 233, 216), 255, LWA_COLORKEY 'RGB(236, 233, 216)表示灰色
End Sub
Private Sub Command2_Click() '将整个窗体设为半透明
SetWindowLong hwnd, GWL_EXSTYLE, WS_EX_LAYERED
SetLayeredWindowAttributes hwnd, 0, 150, LWA_ALPHA '透明度为150,透明度值0~255
End Sub