Announcement

Collapse
No announcement yet.

Detect keypress in a DDT textbox

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Detect keypress in a DDT textbox

    This is probably blindingly simple, but I couldnt find any references in my beloved POFFS...
    Basically I need to be able to detect when Enter is pressed in a DDT textbox
    Thanks!
    Hope youre all enjoying the start of the weekend


    ------------------
    -

  • #2
    Not entirely simple, but following is one way of doing it:
    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Test of subclassed textbox and Enter-key trap
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
     
    %ID_TEXT = 10                         'Id for textbox
    GLOBAL hEdit AS LONG, oldTxtproc AS LONG  'for address of original textbox procedure
    DECLARE CALLBACK FUNCTION DlgProc
    DECLARE CALLBACK FUNCTION TextWndProc
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Create dialog and controls, etc
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN
      LOCAL hDlg AS LONG
     
      DIALOG NEW 0, "Textbox test..", , , 120, 46, %WS_CAPTION or%WS_SYSMENU, 0 TO hDlg
     
      CONTROL ADD TEXTBOX, hDlg, %ID_TEXT, "", 2, 2, 116, 12, _
                           %WS_CHILD OR %WS_HSCROLL, %WS_EX_CLIENTEDGE
      CONTROL HANDLE hDlg, %ID_TEXT TO hEdit
     
      oldTxtproc = SetWindowLong(hEdit, %GWL_WNDPROC, CODEPTR(TextWndProc)) 'Subclass Edit control
     
      DIALOG SHOW MODAL hDlg CALL DlgProc
     
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Main dialog's message handler
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgProc
      SELECT CASE CBMSG
         CASE %WM_DESTROY
            IF oldTxtproc THEN SetWindowLong hEdit, %GWL_WNDPROC, oldTxtproc      'Restore from subclass at exit
     
      END SELECT
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Textbox's subclassed message handler
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION TextWndProc
      SELECT CASE CBMSG
         CASE %WM_KEYUP
            IF CBWPARAM = %VK_RETURN THEN MSGBOX "Enter was pressed"
     
      END SELECT
      FUNCTION = CallWindowProc(oldTxtproc, CBHNDL, CBMSG, CBWPARAM, CBLPARAM)
    END FUNCTION
    ------------------
    Corrected un-subclassing to WM_DESTROY after tips from Lance.

    [This message has been edited by Borje Hagsten (edited April 20, 2001).]

    Comment


    • #3
      Thanks Borje - thats a bit trickier than I thought it would've been, but it works as required nonetheless, thanks!


      ------------------
      -

      Comment


      • #4
        Unfortunately, Borje is unsubclasing the control long after it has been destroyed... this is an incorrect technique.

        The unsubclass code should be placed in the %WM_DESTROY handler of the dialog callback. Search the Source Code Forum subject titles for "subclass" and you'll find my original code for this that shows how to clean up correctly.


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Ah - sorry, I have corrected the code above..

          ------------------

          Comment

          Working...
          X