VB如何实现透明窗体?
发布网友
发布时间:2022-05-20 12:31
我来回答
共2个回答
热心网友
时间:2023-10-19 18:17
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 Sub Form_Load()
Me.BorderStyle = 0
Me.Caption = ""
Me.BackColor = vbRed
SetWindowLong Me.hwnd, -20, GetWindowLong(Me.hwnd, -20) Or &H80000
SetLayeredWindowAttributes Me.hwnd, vbRed, 0, 1
End Sub
热心网友
时间:2023-10-19 18:17
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 LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_COLORKEY = &H1
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 Sub Form_Load()中放入:
Dim rtn1 As Long
rtn1 = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn1 = rtn1 Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn1
SetLayeredWindowAttributes hwnd, RGB(255, 255, 255), 100, LWA_COLORKEY