Where does the listbox Enter Key event go

Started by jcmatt, March 04, 2009, 10:54:55 AM

Previous topic - Next topic

jcmatt

Hi,

There doesn't seem to be any Key events for the listbox control.
Where/how do I detect the Enter key being pressed to select an item in a listbox?

Jim

Pat Dooley

Someone may have a better approach, but this seems to work in the listbox custom event.
Function FORM1_LIST1_CUSTOM ( _
                            ControlIndex  As Long,  _  ' index in Control Array
                            hWndForm      As Dword, _  ' handle of Form
                            hWndControl   As Dword, _  ' handle of Control
                            wMsg          As Long,  _  ' type of message
                            wParam        As Dword, _  ' first message parameter
                            lParam        As Long   _  ' second message parameter
                            ) As Long

Local mystr As String
Local idx As Long

If wParam = %VK_RETURN Then  '%WM_CHAR Then
      'now do something such as...
      idx=FF_ListBox_GetCurSel (HWND_FORM1_LIST1)
      mystr=FF_ListBox_GetText (HWND_FORM1_LIST1, idx)
      FF_TextBox_SetText (HWND_FORM1_TEXT1, mystr)
End If

End Function

Good luck.

Pat

jcmatt


TechSupport

Hi Guys,

Pat, be careful with your approach because you are not filtering out the messages in your CUSTOM message handler. Try the code below (you need the WM_GETDLGCODE to ensure that the keypresses are handled by the ListBox).


Function FORM1_LIST1_CUSTOM ( _
                            ControlIndex  As Long,  _  ' index in Control Array
                            hWndForm      As Dword, _  ' handle of Form
                            hWndControl   As Dword, _  ' handle of Control
                            wMsg          As Long,  _  ' type of message
                            wParam        As Dword, _  ' first message parameter
                            lParam        As Long   _  ' second message parameter
                            ) As Long

   Select Case wMsg

      Case %WM_GETDLGCODE
         Function = %DLGC_WANTALLKEYS
         Exit Function
     
      Case %WM_CHAR
         If wParam = %VK_RETURN Then 
            MsgBox "ENTER key pressed"
         End If

   End Select
   
End Function




Pat Dooley

Thanks Paul for fixing my code. While it seemed to work OK, I thought that it seemed a little simplistic. When it comes to handling Windows messages, I feel like the guy trying to find a black cat in a coal bin at midnight.

TechSupport