Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
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 Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
添加一个command,click中加入
Dim rtn As Long
If f1 Then'f1是个全局的变量
rtn = GetWindowLong(hWnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hWnd, 0, 255, LWA_ALPHA
f1 = False
Else
rtn = GetWindowLong(hWnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hWnd, 0, 150, LWA_ALPHA
f1 = True
End If
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex 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 Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_COLORKEY = &H1
Public Sub TransparenceWindow(hWnd As Long, ByVal lTransparenceColor As Long)
Dim lR As Long
On Error GoTo Err1
lR = GetWindowLong(hWnd, GWL_EXSTYLE)
lR = lR Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, lR
SetLayeredWindowAttributes hWnd, lTransparenceColor, 0, LWA_COLORKEY
Exit Sub
Err1:
End Sub
Private Sub Command1_Click()
Me.Label1.BackColor = RGB(0, 255, 0)
TransparenceWindow Me.hWnd, Me.Label1.BackColor
End Sub
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
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 Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Function SetDarkForm(ByRef pFrm As Form) As Boolean
Dim lRtn As Long
lRtn = GetWindowLong(pFrm.hwnd, GWL_EXSTYLE)
lRtn = lRtn Or WS_EX_LAYERED
SetWindowLong pFrm.hwnd, GWL_EXSTYLE, lRtn
SetLayeredWindowAttributes pFrm.hwnd, 0, 200, LWA_ALPHA
End Function