Message Pump

Started by Richard Kelly, November 19, 2011, 03:23:51 AM

Previous topic - Next topic

Richard Kelly

This is my first time getting into the FF message pump. What I'm trying to do is to have the Enter key act like a tab on all single line text boxes and like a mouse click on buttons. I included buttons because I noticed that on a form, if I press Enter on a button and there is a error message and focus is transferred to another control on the same form, the next Enter key on the same button does nothing.

Is this code the "right" way to do these things?


Function FF_PUMPHOOK( Msg As tagMsg ) As Long


   ' If this function returns FALSE (zero) then the processing of the regular
   ' FireFly message pump will continue. Returning TRUE (non-zero) will bypass
   ' the regular message pump.
   
Static szClass          As Asciiz * 10
   
    Select Case Msg.Message
     
        Case %WM_KEYDOWN
       
            Select Case Msg.wParam
           
                Case = %VK_RETURN
               
' Convert return (enter) key to a tab key for all single line textboxes
               
                    GetClassName Msg.hWnd, szClass, SizeOf(szClass)
                   
                    Select Case UCase$(szClass)
                   
                        Case = "EDIT"

                            If (GetWindowLong(Msg.hWnd, %GWL_STYLE) And %ES_MULTILINE ) <> %ES_MULTILINE Then
                       
' Change the key to be a "TAB" that will move us to the next control

                                Msg.wParam = %VK_TAB
                               
                            End If
                       
                        Case = "BUTTON"

' Simulate a mouse click on the button

                            SendMessage (Msg.hWnd, %BM_CLICK, 0, 0)
                       
                    End Select
               
            End Select
           
    End Select

   Function = %FALSE    'return %TRUE if you need to bypass the FireFly message pump

   ' If you are dealing with a 'normal' OCX control then the following code will
   ' allow the message to be forwarded to the OCX.
   #If %USEOLECON = 1
      Function = OC_ForwardMessage( GetFocus(), Msg)
   #EndIf
End Function


Rick Kelly

Klaas Holland

This is what Paul instructed me for the BUTTON Key.


   ' Filter the ENTER key for the command buttons
   Select Case Msg.Message
     
      Case %WM_KEYDOWN
         Local hFocus    As Dword
         Local idControl As Long 
         
         hFocus      = GetFocus()
         
         If Msg.wParam = %VK_RETURN Then
            ' Only handle the ENTER key for the CommandButtons that we are interested in.
            Static zClass As Asciiz * 50
            GetClassName Msg.hWnd, zClass, SizeOf(zClass)
            If UCase$(zClass) = "BUTTON" Then
                idControl = GetWindowLong( hFocus, %GWL_ID )
                SendMessage GetParent(hFocus), %WM_COMMAND, Mak( Long, idControl, %BN_CLICKED), hFocus
                Msg.Message = %WM_NULL
            End If   
        End If   
       
    End Select