Results 1 to 3 of 3

Thread: HotKey for Application

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Minsk, Belarus
    Posts
    11

    Post

    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?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    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..
    Code:
    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..
    Code:
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Minsk, Belarus
    Posts
    11

    Post

    Thanks a lot, Aaron. It works great.




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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width