Option Explicit ' ******************** 窗体透明 ******************** '***Module.bas '**** Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long Public Const WS_EX_LAYERED = &H80000 Public Const GWL_EXSTYLE = (-20) Public Const LWA_ALPHA = &H2 Public Const LWA_COLORKEY = &H1 Public Const WS_EX_TRANSPARENT = &H20& '************** '***Form1.frm '-------------------------------------------------** Private Sub Form_Load() Dim rtn As Long rtn = GetWindowLong(hwnd, GWL_EXSTYLE) '全窗体 完全透明, 通透 全消失 ' SetWindowLong hwnd, GWL_EXSTYLE, rtn Or WS_EX_LAYERED ' '将某个色彩 完全通透 部分消失 ' lbl.BackColor = vbBlue '设置一个色彩 ' Form1.BackColor = vbBlue ' SetWindowLong hwnd, GWL_EXSTYLE, rtn Or WS_EX_LAYERED ' SetLayeredWindowAttributes hwnd, vbBlue, 0, LWA_COLORKEY ' '通透 , 半透明 ' SetWindowLong Me.hwnd, GWL_EXSTYLE, rtn Or WS_EX_LAYERED Or WS_EX_TRANSPARENT ' SetLayeredWindowAttributes Me.hwnd, 0, 128, LWA_ALPHA ' The level of transparency (0 - 255) '不通透, 半透明 SetWindowLong hwnd, GWL_EXSTYLE, rtn Or WS_EX_LAYERED SetLayeredWindowAttributes hwnd, 0, 200, LWA_ALPHA '(句柄 ,掩码颜色[RGB] , 透明程度[0-255], ) 'hwnd 'crKey 为颜色值,// 掩码的颜色,可以用RGB(r,g,b)来指定 'bAlpha 是透明度,取值范围是[0,255] 'dwFlags 是透明方式,可以取两个值: ' =LWA_ALPHA时,crKey参数无效,bAlpha参数有效; ' =LWA_COLORKEY时,窗体中的所有颜色为crKey的地方将变为透明,bAlpha参数无效。 ' End Sub
摘自QQ群