设置快捷键的方式

 

Declare Function CallWindowProc Lib "USER32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function GetWindowLong Lib "USER32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "USER32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Declare Function RegisterHotKey Lib "USER32" (ByVal hWnd As Long, ByVal ID As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "USER32" (ByVal hWnd As Long, ByVal ID As Long) As Long
Public Const WM_HOTKEY = &H312

 

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 GetWindowLong Lib "USER32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long

 

 

Dim dt As Long
dt = RegisterHotKey(Me.hWnd, 10001, 0, vbKeyS)
dt = RegisterHotKey(Me.hWnd, 10002, 0, vbKeyC)
dt = RegisterHotKey(Me.hWnd, 10003, 0, vbKeyK)

 


prevWndProc = GetWindowLong(Me.hWnd, GWL_WNDPROC)
SetWindowLong Me.hWnd, GWL_WNDPROC, AddressOf WndProcB

 

 

 

Function WndProcB(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

If Msg = WM_HOTKEY Then
frmCali.keypress lParam
End If
WndProcB = CallWindowProc(prevWndProc, hWnd, Msg, wParam, lParam)
End Function

你可能感兴趣的:(快捷键)