1.
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long
Dim GC1&, GC2&
Private Sub MDIForm_Load()
GC1 = GetSysColor(2)
GC2 = GetSysColor(27)
SetSysColors 1, 2, RGB(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256))
End Sub
Private Sub MDIForm_Unload(Cancel As Integer)
SetSysColors 1, 2, GC1
SetSysColors 1, 27, GC2
End Sub
2.
'标准模块
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 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 Const GWL_EXSTYLE = (-20)
Public Const WS_EX_LAYERED = &H80000
Public Const LWA_ALPHA = &H2
Public Sub TransparentForm(hwnd As Long, i As Integer)
Dim Rtn As Long
Rtn = GetWindowLong(hwnd, GWL_EXSTYLE) '注释:取的窗口原先的样式
Rtn = Rtn Or WS_EX_LAYERED '注释:使窗体添加上新的样式WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, Rtn '注释:把新的样式赋给窗体
SetLayeredWindowAttributes hwnd, 0, i, LWA_ALPHA
End Sub
'窗体中调用TransparentForm,参数hwnd为目标窗体句柄,i为透明度(1~255)