VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Creates a hotkey for your program

by Sam Huggill (7 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Wed 2nd June 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Creates a hotkey for your program

API Declarations


"SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Long) As Long

Declare Function DefWindowProc Lib "user32" _
Alias "DefWindowProcA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long

Public Const WM_SETHOTKEY = &H32
Public Const WM_SHOWWINDOW = &H18
Public Const HK_SHIFTA = &H141 'Shift + A
Public Const HK_SHIFTB = &H142 'Shift * B
Public Const HK_CONTROLA = &H241 'Control + A
Public Const HK_ALTZ = &H45A

'The value of the key-combination has to
'declared in lowbyte/highbyte-format

'That means as a hex-number: the last two
'characters specify the lowbyte (e.g.: 41 = a),
'the first the highbyte (e.g.: 01 = 1 = Shift)

Rate Creates a hotkey for your program



Me.WindowState = vbMinimized
'Let windows know what hotkey you want for
'your app, setting of lParam has no effect
erg& = SendMessage(Me.hwnd, WM_SETHOTKEY, _
HK_ALTZ, 0)
'Check if succesfull
If erg& <> 1 Then
MsgBox "You need another hotkey", vbOKOnly, _
"Error"
End If

'Tell windows what it should do, when the hotkey
'is pressed -> show the window!
'The setting of wParam and lParam has no effect

erg& = DefWindowProc(Me.hwnd, WM_SHOWWINDOW, _
0, 0)
End Sub
'Note: Press Alt + Z to show the form.

Download this snippet    Add to My Saved Code

Creates a hotkey for your program Comments

No comments have been posted about Creates a hotkey for your program. Why not be the first to post a comment about Creates a hotkey for your program.

Post your comment

Subject:
Message:
0/1000 characters