Page 1 of 1

TListBox refinement

PostPosted: Mon Feb 06, 2006 8:44 am
by Enrico Maria Giordano
The following sample shows that the Return key is not trapped by bKeyDown codeblock:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    LOCAL oLbx

    LOCAL cVar := ""

    DEFINE DIALOG oDlg

    @ 1, 1 LISTBOX oLbx VAR cVar ITEMS { "Bert", "Carl", "William" }

    oLbx:bKeyDown = { | nKey | MsgInfo( nKey ) }

    @ 3, 1 BUTTON "&Close" ACTION oDlg:End()

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


A possible solution is to add the following method to TListBox class:

Code: Select all  Expand view
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TListBox

   if nMsg == WM_GETDLGCODE .and. nWParam == VK_RETURN
      ::oWnd:nLastKey := VK_RETURN
      return Super:KeyDown( nWParam, nLParam )
   endif

return Super:HandleEvent( nMsg, nWParam, nLParam )


EMG

PostPosted: Mon Feb 06, 2006 9:27 pm
by James Bott
Enrico,

It is curious that if you put the listbox on a Window then the Enter key can be trapped with bKeydown. I have not figured out why this is.

James

PostPosted: Mon Feb 06, 2006 10:42 pm
by Enrico Maria Giordano
James Bott wrote:Enrico,

It is curious that if you put the listbox on a Window then the Enter key can be trapped with bKeydown. I have not figured out why this is.

James


I don't know either. :-(

By the way: you look great! :-)

EMG

PostPosted: Tue Feb 07, 2006 10:27 am
by Antonio Linares
Enrico,

WM_GETDLGCODE doesn't supply any parameters. Is it an undocumented feature that the keystroke is provided ? Thanks,

PostPosted: Tue Feb 07, 2006 10:42 am
by Enrico Maria Giordano
I don't know, sorry, but it works. :-)

EMG

PostPosted: Tue Feb 07, 2006 10:46 am
by Antonio Linares
Enrico,

ok, added :)

Thanks!

PostPosted: Tue Feb 07, 2006 10:46 am
by Enrico Maria Giordano
Thank you!

EMG