Date: 02-16-2022
Return to Index
created by gbSnippets
'Desktop shortcut tells the Windows OS to open an application
'Hotkeys tell the Windows OS to display a window from an already opened application
'Accelerator keys tell a running app to execute a menu option
'Use the RegisterHotKey API to register a key combination with Windows.
'When the key combination is pressed, the application receives a %WM_HotKey
'message. CB.wParam contains the ID of the registered hot key.
'Primary Code:
Local iResult&
iResult& = RegisterHotKey hDlg, %IDM_HotKey, %HotKeyF_Control, %vk_h 'Ctrl-H
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "CommCtrl.inc"
Global hDlg As Dword
%IDM_HotKey = 500
Function PBMain() As Long
Dialog New Pixels, 0, "Hotkey Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local iResult&
Select Case CB.Msg
Case %WM_InitDialog
iResult& = RegisterHotKey (CB.Hndl, %IDM_HotKey, %HotKeyF_Control, %vk_h) 'Ctrl-H
If iResult& = 0 Then MsgBox "Cannot register Ctrl-H hot key!"
Case %WM_HotKey
Select Case CB.wParam
Case %IDM_HotKey
Dialog Show State hDlg, %SW_Restore
End Select
End Select
End Function
'gbs_00053
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm