Module1:
Option Explicit
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 FormState As Boolean
Public FormTranValue As Integer
Public Sub TranForm() '窗体半透明
Dim rtn As Long
rtn = GetWindowLong(Form1.hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong Form1.hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes Form1.hwnd, 0, FormTranValue, LWA_ALPHA
End Sub
Public Sub FormShow() '窗体显示
Dim rtn As Long
rtn = GetWindowLong(Form1.hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong Form1.hwnd, GWL_EXSTYLE, rtn
Do Until FormTranValue = 150
Delay (10)
FormTranValue = FormTranValue + 10
SetLayeredWindowAttributes Form1.hwnd, 0, FormTranValue, LWA_ALPHA
Loop
End Sub
Public Sub FormClose()
Dim rtn As Long
rtn = GetWindowLong(Form1.hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong Form1.hwnd, GWL_EXSTYLE, rtn
Do Until FormTranValue = 0
Delay (10)
FormTranValue = FormTranValue - 10
SetLayeredWindowAttributes Form1.hwnd, 0, FormTranValue, LWA_ALPHA
Loop
End Sub
Module2:
Option Explicit
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Public hHook
Public Function MyKBHook(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If nCode <> 0 Then
If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("Q") Then
If FormState = False Then
FormShow
'FormState = True
Else
FormClose
'FormState = False
End If
End If
End If
End Function
Module3:
Option Explicit
Public Declare Function timeGetTime Lib "winmm.dll" () As Long
Public Sub Delay(T As Long)
Dim Savetime As Long
Savetime = timeGetTime
While timeGetTime < Savetime + T
DoEvents
Wend
End Sub
Form1:
Private Sub Form_Load()
FormState=False
TranForm
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf MyKBHook, 0, App.ThreadID)
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx hHook
End Sub
Option Explicit
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 FormState As Boolean
Public FormTranValue As Integer
Public Sub TranForm() '窗体半透明
Dim rtn As Long
rtn = GetWindowLong(Form1.hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong Form1.hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes Form1.hwnd, 0, FormTranValue, LWA_ALPHA
End Sub
Public Sub FormShow() '窗体显示
Dim rtn As Long
rtn = GetWindowLong(Form1.hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong Form1.hwnd, GWL_EXSTYLE, rtn
Do Until FormTranValue = 150
Delay (10)
FormTranValue = FormTranValue + 10
SetLayeredWindowAttributes Form1.hwnd, 0, FormTranValue, LWA_ALPHA
Loop
End Sub
Public Sub FormClose()
Dim rtn As Long
rtn = GetWindowLong(Form1.hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong Form1.hwnd, GWL_EXSTYLE, rtn
Do Until FormTranValue = 0
Delay (10)
FormTranValue = FormTranValue - 10
SetLayeredWindowAttributes Form1.hwnd, 0, FormTranValue, LWA_ALPHA
Loop
End Sub
Module2:
Option Explicit
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Public hHook
Public Function MyKBHook(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If nCode <> 0 Then
If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("Q") Then
If FormState = False Then
FormShow
'FormState = True
Else
FormClose
'FormState = False
End If
End If
End If
End Function
Module3:
Option Explicit
Public Declare Function timeGetTime Lib "winmm.dll" () As Long
Public Sub Delay(T As Long)
Dim Savetime As Long
Savetime = timeGetTime
While timeGetTime < Savetime + T
DoEvents
Wend
End Sub
Form1:
Private Sub Form_Load()
FormState=False
TranForm
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf MyKBHook, 0, App.ThreadID)
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx hHook
End Sub
