clefus
Nov 12th, 1999, 10:49 AM
How do u assign a hotkey for a hidden form that is loaded, but like I said it is hidden, so it can't have the focus.
Aaron Young
Nov 12th, 1999, 11:00 AM
2 Methods..
You could Fake a HotKey using the GetAsyncKeystate API within a Timer Event, eg.
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Const VK_CONTROL = &H11
Private Sub Timer1_Timer()
If GetAsyncKeyState(VK_CONTROL) And GetAsyncKeyState(vbKeyZ) Then
Caption = "Zoom"
Else
Caption = ""
End If
End Sub
If you want a True HotKey, you need to use the RegisterHotKey API and SubClassing, eg.
In a Module..
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
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 Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2
Public Const MOD_SHIFT = &H4
Public Const GWL_WNDPROC = (-4)
Private Const WM_HOTKEY = &H312
Public lPrevWnd As Long
Public Function SubWindow(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
'Your HotKey's Been Triggered!
Form1.Show
MsgBox "HotKey Activated", vbInformation + vbOKOnly, "HotKey"
End If
SubWindow = CallWindowProc(lPrevWnd, hwnd, Msg, wParam, ByVal lParam)
End Function
In the Form..
Private Sub Form_Load()
Call RegisterHotKey(hwnd, 1, MOD_CONTROL, vbKeyZ)
lPrevWnd = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf SubWindow)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnregisterHotKey(hwnd, 1)
'Always Close the Form Properly or VB will Crash!
Call SetWindowLong(hwnd, GWL_WNDPROC, lPrevWnd)
End Sub
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net
[This message has been edited by Aaron Young (edited 11-13-1999).]
clefus
Nov 13th, 1999, 01:36 AM
Thanks, that worked just like I wanted it to...