新建一工程,放三个按钮分别为command1、command2、command3,拷贝下列代码,可实现窗体透明、半透明、不透明功能,使用透明功能你可以随便用那个pset画点、line画线、print打印字符
'-------------------------拷贝下列代码------------------------------------------------------------
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 WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = -20
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Sub Command1_Click()
'透明
Dim rtn As Long
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, Me.BackColor, 0, LWA_COLORKEY
End Sub
Private Sub Command2_Click()
'半透明
Dim rtn As Long
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, 0, 100, LWA_ALPHA
End Sub
Private Sub Command3_Click()
'不透明
Dim rtn As Long
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, 0, 255, LWA_ALPHA
End Sub
Sub Form_Load()
Me.BackColor = &HE0E0E0
'颜色值必须小于&H80000000
End Sub