Announcement

Collapse
No announcement yet.

Subclassing DDT TextBox

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

  • Borje Hagsten
    replied
    Following maybe can be of help:
    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Test of sub-classed textbox
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    %ID_TEXT = 20
    DECLARE CALLBACK FUNCTION DlgProc() AS LONG
    DECLARE CALLBACK FUNCTION TextProc() AS LONG
    GLOBAL OldTextProc AS LONG
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Create dialog and controls, etc
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg AS LONG
      DIALOG NEW 0, "Edit Subclass test ",,, 180, 38, %WS_SYSMENU, 0 TO hDlg
      CONTROL ADD TEXTBOX, hDlg, %ID_TEXT, "Press Enter or Esc..", _
                           4, 4, 167, 14, %WS_CHILD, %WS_EX_CLIENTEDGE CALL DlgProc
     'Subclass textbox
      OldTextProc = SetWindowLong(GetDlgItem(hDlg, %ID_TEXT), %GWL_WNDPROC, CODEPTR(TextProc))
      DIALOG SHOW MODAL hDlg CALL DlgProc
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Main callback
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgProc() AS LONG
      SELECT CASE CBMSG
         CASE %WM_KILLFOCUS '<- to avoid "auto" selection of text in textbox when focus changes..
            CONTROL SEND CBHNDL, %ID_TEXT, %EM_SETSEL, 65000, 65000 '<- set caret to end pos
     
         CASE %WM_COMMAND
            IF CBCTLMSG =%EN_CHANGE THEN       '<- notifications goes to parent..
               BEEP
            ELSEIF CBCTLMSG=%EN_SETFOCUS THEN
            ELSEIF CBCTLMSG=%EN_KILLFOCUS THEN
            END IF
     
         CASE %WM_DESTROY                      '<- un-subclass textbox
            SetWindowLong GetDlgItem(CBHNDL, %ID_TEXT), %GWL_WNDPROC, OldTextProc
      END SELECT
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Text control subclass
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION TextProc                 '<- other messages to here
      SELECT CASE CBMSG
         CASE %WM_KEYUP
            IF CBWPARAM = %VK_ESCAPE THEN      '<- Esc pressed
               MSGBOX "yo"
            ELSEIF CBWPARAM = %VK_RETURN THEN  '<- Enter pressed
               BEEP
            END IF
     
      END SELECT
      FUNCTION = CallWindowProc(OldTextProc, CBHNDL, CBMSG, CBWPARAM, CBLPARAM)
    END FUNCTION

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

    Leave a comment:


  • Gregery D Engle
    started a topic Subclassing DDT TextBox

    Subclassing DDT TextBox

    Here is the callback:

    I'm wanting to trap when a user pressed the ENTER key or the
    ESC key. I know I will probably have to subclass the control,
    anyone have an easy way to do this?

    Thanks

    Code:
    Callback Function CBF_FORM1_TEXT1
        Select Case Cbmsg
            Case %WM_KEYUP
                MsgBox Str$(Cbwparam)
                If Cbwparam = 27 Then MsgBox "yo"
                If Cbwparam = 13 Then Beep
        End Select
    
        If Cbctlmsg=%EN_CHANGE Then
        
        End If
        
        If Cbctlmsg=%EN_SETFOCUS Then
        
        End If
        If Cbctlmsg=%EN_KILLFOCUS Then
    
        End If
    End Function
    ------------------
    -Greg
Working...
X