2个回答
展开全部
'点击窗体隐藏,按Alt + Tab回调窗体
Option Explicit
Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString _
As String) As Integer
'为全局热键添加一个标识符
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal ID As Long, _
ByVal fsModifiers As Long, ByVal vk As Long) As Long
'hWnd:接收热键产生WM_HOTKEY消息的窗口句柄
'id:定义热键的标识符,GlobalAddAtom函数获得热键的标识符.
'MOD_ALT为Alt键,MOD_CONTROL为Ctrl键,MOD_SHIFT为Shift键,MOD_WIN为Windows按键。
'vk:定义热键的虚拟键码。
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal ID As Long _
) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal _
hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal _
wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Const MOD_ALT = &H1
Const PM_REMOVE = &H1
Const WM_HOTKEY = &H312
Dim HotKey_ID As Long
Private HotKey_Flg As Boolean
Dim Message As Msg
Private Sub Form_Click()
Me.Hide
HotKey_ID = GlobalAddAtom("Alt + Tab")
'RegisterHotKey Me.hWnd, &HBFFF&, MOD_CONTROL + MOD_ALT, vbKeyG '注册 Ctrl+Alt+ G 为热键
RegisterHotKey Me.hWnd, HotKey_ID, MOD_ALT, 9 '注册 Ctrl+Alt+ G 为热键
Me.Hide
HotKey_Flg = False
Do While Not HotKey_Flg
WaitMessage '等待消息
If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then '检查是否热键被按下
''''可以在此写入你要阻止的代码
Me.Show
End If
DoEvents '转让控制权,允许操作系统处理其他事件
Loop
End Sub
Private Sub Form_Unload(Cancel As Integer) '撤销热键的注册
HotKey_Flg = True
Call UnregisterHotKey(Me.hWnd, HotKey_ID)
End Sub
Option Explicit
Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString _
As String) As Integer
'为全局热键添加一个标识符
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal ID As Long, _
ByVal fsModifiers As Long, ByVal vk As Long) As Long
'hWnd:接收热键产生WM_HOTKEY消息的窗口句柄
'id:定义热键的标识符,GlobalAddAtom函数获得热键的标识符.
'MOD_ALT为Alt键,MOD_CONTROL为Ctrl键,MOD_SHIFT为Shift键,MOD_WIN为Windows按键。
'vk:定义热键的虚拟键码。
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal ID As Long _
) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal _
hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal _
wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Const MOD_ALT = &H1
Const PM_REMOVE = &H1
Const WM_HOTKEY = &H312
Dim HotKey_ID As Long
Private HotKey_Flg As Boolean
Dim Message As Msg
Private Sub Form_Click()
Me.Hide
HotKey_ID = GlobalAddAtom("Alt + Tab")
'RegisterHotKey Me.hWnd, &HBFFF&, MOD_CONTROL + MOD_ALT, vbKeyG '注册 Ctrl+Alt+ G 为热键
RegisterHotKey Me.hWnd, HotKey_ID, MOD_ALT, 9 '注册 Ctrl+Alt+ G 为热键
Me.Hide
HotKey_Flg = False
Do While Not HotKey_Flg
WaitMessage '等待消息
If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then '检查是否热键被按下
''''可以在此写入你要阻止的代码
Me.Show
End If
DoEvents '转让控制权,允许操作系统处理其他事件
Loop
End Sub
Private Sub Form_Unload(Cancel As Integer) '撤销热键的注册
HotKey_Flg = True
Call UnregisterHotKey(Me.hWnd, HotKey_ID)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询