- UID
- 220677
- 帖子
- 31
- 主題
- 3
- 精華
- 0
- 積分
- 4
- 楓幣
- 77
- 威望
- 2
- 存款
- 0
- 贊助金額
- 0
- 推廣
- 0
- GP
- 2
- 閱讀權限
- 10
- 性別
- 男
- 在線時間
- 41 小時
- 註冊時間
- 2018-1-24
- 最後登入
- 2020-3-21
|
洋洋技術 發表於 2018-2-14 17:12
之後我會新增快捷鍵的~~
' --------------------------------------------------------------------------------------
'声明注册热键API函数
Public Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Integer, ByVal id As Integer,
ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
'声明注销热键API函数
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Integer, ByVal id As Integer) As Integer
Public Const WM_HOTKEY As Short = &H312S '热键消息ID,此值固定,不能修改
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
RegisterHotKey(Me.Handle.ToInt32, 1, Nothing, Keys.F3) '注册的热键为F3
RegisterHotKey(Me.Handle.ToInt32, 2, Nothing, Keys.F5) '注册的热键为F5
RegisterHotKey(Me.Handle.ToInt32, 3, Nothing, Keys.F2) '注册的热键为F2
End Sub
'窗体的消息处理函数
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_HOTKEY Then '判断是否为热键消息
Select Case m.WParam.ToInt32 '判断热键消息的注册ID
Case 1
If CheckBox5.Checked = True Then
CheckBox5.Checked = False
Else
CheckBox5.Checked = True
End If
' 计数1 = 计数1 + 1 '两种方法
' CheckBox5.Checked = True
' If 计数1 > 1 Then
' CheckBox5.Checked = False
' 计数1 = 0
' End If
Case 2
If CheckBox7.Checked = True Then
CheckBox7.Checked = False
Else
CheckBox7.Checked = True
End If
Case 3
If CheckBox4.Checked = True Then
CheckBox4.Checked = False
Else
CheckBox4.Checked = True
End If
End Select
End If
MyBase.WndProc(m) '循环监听消息
End Sub
'最后别忘记注销热键哦
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
UnregisterHotKey(Me.Handle.ToInt32, Keys.F3)
UnregisterHotKey(Me.Handle.ToInt32, Keys.F2)
UnregisterHotKey(Me.Handle.ToInt32, Keys.F5)
End Sub |
|