source code hotkey control

Download Source Code Hotkey Control

If you can't read please download the document

Upload: gilang-on-wp

Post on 18-Dec-2015

233 views

Category:

Documents


1 download

DESCRIPTION

VB6

TRANSCRIPT

What is a Hot Key ControlA hot key is a key combination that the user can press to perform an action quickly. For example, a user can create a hot key that activates a given window and brings it to the top of the z-order. The hot key control displays the user's choices and ensures that the user selects a valid key combination. Here's the code below on how to create a hot key control.Declare Function SendMessage Lib "user32" Alias _"SendMessageA" (ByVal hwnd As Long, _ByVal wMsg As Long, ByVal wParam As Long, _lParam As Long) As LongDeclare Function DefWindowProc Lib "user32" _Alias "DefWindowProcA" (ByVal hwnd As Long, _ByVal wMsg As Long, ByVal wParam As Long, _ByVal lParam As Long) As LongPublic Const WM_SETHOTKEY = &H32Public Const WM_SHOWWINDOW = &H18Public Const HK_SHIFTA = &H141 'Shift + APublic Const HK_SHIFTB = &H142 'Shift * BPublic Const HK_CONTROLA = &H241 'Control + APublic 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)Private Sub Form_Load()Me.WindowState = vbMinimized'Let windows know what hotkey you want for'your app, setting of lParam has no effecterg& = SendMessage(Me.hwnd, WM_SETHOTKEY, _HK_ALTZ, 0)'Check if succesfullIf erg& 1 ThenMsgBox "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 effecterg& = DefWindowProc(Me.hwnd, WM_SHOWWINDOW, _0, 0)End Sub