PDA

Click to See Complete Forum and Search --> : HotKey for Application


Vova
Nov 1st, 1999, 07:34 PM
There is a tip "Creating a HotKey for your application" (please, look at "Tips", page 5). I can't understand which event takes place when user presses HotKey. It looks like
Activate and Resize don't go for that. Does anybody know what is the matter here?

Aaron Young
Nov 2nd, 1999, 03:20 AM
To make it do something more meaningful with the HotKey you need to Subclass the Form and Capture the HotKey Message, eg.

In a Module..

Private 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
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 Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Const WM_HOTKEY = &H312
Public Const GWL_WNDPROC = (-4)
Public Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2

Public lPrevWndProc As Long

Function SubClassedWnd(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_HOTKEY And wParam = 1 Then
'HotKey Pressed
'Do What You Want Here.
End If
SubClassedWnd = CallWindowProc(lPrevWndProc, hWnd, Msg, wParam, lParam)
End Function

In the Form..

Private Sub Form_Load()
lPrevWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf SubClassedWnd)
'Register the HotKey CTRL + ALT + A
Call RegisterHotKey(hWnd, 1, MOD_CONTROL Or MOD_ALT, vbKeyA)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call UnregisterHotKey(hWnd, 1)
Call SetWindowLong(hWnd, GWL_WNDPROC, lPrevWndProc)
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

Vova
Nov 2nd, 1999, 03:06 PM
Thanks a lot, Aaron. It works great.




[This message has been edited by Vova (edited 11-03-1999).]