Results 1 to 2 of 2

Thread: short cut key for button on mdi form

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    8

    Exclamation short cut key for button on mdi form

    How can i give shortcut key to any button placed on mdi form(I have one picture box on mdi form and button is placed on that picture box) and could access from any child forms and I dont have any menu on mdi form.Pls help me.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: short cut key for button on mdi form

    Welcome to the forums.

    Try creating a system wide hotkey
    Code:
    Private Const MOD_ALT = &H1
    Private Const MOD_CONTROL = &H2
    Private Const MOD_SHIFT = &H4
    Private Const PM_REMOVE = &H1
    Private Const WM_HOTKEY = &H312
    
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    
    Private Type Msg
        hWnd As Long
        Message As Long
        wParam As Long
        lParam As Long
        time As Long
        pt As POINTAPI
    End Type
    
    Private Declare Function RegisterHotKey Lib "user32" _
    (ByVal hWnd As Long, _
    ByVal id As Long, _
    ByVal fsModifiers As Long, _
    ByVal vk As Long) As Long
    
    Private Declare Function UnregisterHotKey Lib "user32" _
    (ByVal hWnd As Long, _
    ByVal id As Long) As Long
    
    Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" _
    (lpMsg As Msg, _
    ByVal hWnd As Long, _
    ByVal wMsgFilterMin As Long, _
    ByVal wMsgFilterMax As Long, _
    ByVal wRemoveMsg As Long) As Long
    
    Private Declare Function WaitMessage Lib "user32" () As Long
    
    Private bCancel As Boolean
    
    Private Sub ProcessMessages()
        Dim Message As Msg
        'loop until bCancel is set to True
        Do While Not bCancel
            'wait for a message
            WaitMessage
            'check if it's a HOTKEY-message
            If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
                'minimize the form
                WindowState = vbMinimized
            End If
            'let the operating system process other events
            DoEvents
        Loop
    End Sub
    
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim ret As Long
        bCancel = False
        'register the Ctrl-F hotkey
        ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyZ)
        'show some information
        Me.AutoRedraw = True
        Me.Print "Press CTRL-Z to minimize this form"
        'show the form and
        Show
        'process the Hotkey messages
        ProcessMessages
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        bCancel = True
        'unregister hotkey
        Call UnregisterHotKey(Me.hWnd, &HBFFF&)
    End Sub

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