Announcement

Collapse
No announcement yet.

Keyboard subclassing using DDT

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

  • Lance Edmonds
    replied
    The instance subclass callback function "SubclassProc()" intercepts the keystroke messages. You'll find the details of what wParam and lParam contain in the relevant sections of WIN32.HLP - see WM_KEYDOWN, WM_KEYUP, WM_CHAR, etc.

    Subclassing is discussed in (wait for it!) the Petzold and Rector/Newcomer book's...

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

    Leave a comment:


  • Mike Doty
    replied
    'Lance, saw your subclassing posting
    'How/where is the value of the key pressed obtained?
    'Example: User pressed "A" or "a" or "1" so get a
    'record, etc and continue processing.
    '
    'It would be really great to be able to float a
    'dialog around the screen go get input at any location.
    'This would allow drawing a graphical system then just
    'putting an input control on it.
    '
    'To go even a little future, a picture of a keyboard
    'could be shown on the screen so the user could click
    'instead of type.
    'Thanks, Mike
    '
    Code:
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    
    GLOBAL gOldSubClassProc&
    
    CALLBACK FUNCTION AnyButton
        DIALOG END CBHNDL, ABS(CBCTL = %IDOK)
    END FUNCTION
    
    CALLBACK FUNCTION EditCallback
        ' This is the callback function.
        ' We can't intercept keyboard messages like this, we need to subclass...
        IF CBMSG = %WM_KEYUP THEN MSGBOX "TADA"
    END FUNCTION
    
    CALLBACK FUNCTION DlgCallBack
        LOCAL hEdit&
        SELECT CASE CBMSG
            CASE %WM_INITDIALOG
                ' Subclass the edit control
                CONTROL HANDLE CBHNDL, 102 TO hEdit&
                gOldSubClassProc = SetWindowLong(hEdit&, %GWL_WNDPROC, CODEPTR(SubClassProc))
            CASE %WM_DESTROY
                ' Important! Remove the subclassing
                SetWindowLong hEdit&, %GWL_WNDPROC, gOldSubClassProc
        END SELECT
    END FUNCTION
    
    FUNCTION PBMAIN
        #REGISTER NONE
        REGISTER hDlg&
        LOCAL Result&
    
        DIALOG NEW 0, "Subclassed EDIT control with DDT Example",,, 240, 180, %DS_CENTER OR %WS_SYSMENU _
            OR %DS_CONTEXTHELP OR %WS_THICKFRAME OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN, TO hDlg
    
        CONTROL ADD BUTTON,   hDlg, %IDOK,     "&Ok",     190, 10, 40, 14 CALL AnyButton
        CONTROL ADD BUTTON,   hDlg, %IDCANCEL, "&Cancel", 190, 25, 40, 14 CALL AnyButton
        CONTROL ADD COMBOBOX, hDlg, 101,, 10, 10, 170, 100, %CBS_DROPDOWNLIST OR %WS_TABSTOP
        CONTROL ADD TEXTBOX,  hDlg, 102, "This is an edit control", 10, 30, 170, 130, %ES_MULTILINE _
            OR %ES_WANTRETURN OR %WS_BORDER OR %WS_HSCROLL OR %WS_VSCROLL OR %WS_TABSTOP, _
            %WS_EX_CLIENTEDGE CALL EditCallBack
        COMBOBOX ADD hDlg, 101, "This is a combo box!"
        COMBOBOX SELECT hDlg, 101, 1
    
        FOR x& = 1 TO 10
            a$ = a$ + $TAB + FORMAT$(RND(1) * 100000!, "$#######.##") + $CRLF
        NEXT x&
        CONTROL SET TEXT hDlg, 102, a$ + a$
    
        hFont& = GetStockObject(%SYSTEM_FIXED_FONT)
        CONTROL SEND hDlg, 102, %WM_SETFONT, hFont&, %TRUE
        DIALOG SHOW MODAL hDlg CALL DlgCallBack
        'Not executed until dialog finishes
    END FUNCTION
    
    FUNCTION SubClassProc(BYVAL hWnd&, BYVAL wMsg&, BYVAL wParam&, BYVAL lParam&) AS LONG
        ' Process our messages in this subclass procedure
        SELECT CASE wMsg&
            CASE %WM_KEYDOWN
                SetWindowText GetParent(hWnd&), "WM_KEYDOWN"
            CASE %WM_KEYUP
                SetWindowText GetParent(hWnd&), "WM_KEYUP"
            CASE %WM_CHAR
                SetWindowText GetParent(hWnd&), "WM_CHAR"
        END SELECT
        ' Pass the message on to the original window procedure... the DDT engine!
        FUNCTION = CallWindowProc(gOldSubClassProc, hWnd&, wMsg&, wParam&, lParam&)
    END FUNCTION
    ------------------

    Leave a comment:


  • Scott Turchin
    replied
    Hmmmm That's what I had, with one exception:


    GetParent(hWnd&)


    Thanks!

    Scott


    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lance Edmonds
    replied
    take a look at


    ------------------
    lance
    powerbasic support
    mailto:[email protected][email protected]</a>

    Leave a comment:


  • Scott Turchin
    started a topic Keyboard subclassing using DDT

    Keyboard subclassing using DDT

    I created a textbox, told it to call KeyboardCallback.

    Life is good, I can type in the box, must be working...

    I need to scan what is being typed in there however.

    I'm trying to keep ZERO global variables right now unless they are essential.

    Since DDT works and I don't need globals to operate a dialog (thanks Lance and everyone, finally learning!)...


    I wrote this, and it DID work as a subclass routine the old fashioned way, but I took that part out..

    I'm tired and it's after midnight, so maybe I just didn't see somethign I should have...


    It does not return however....Am I not checking the right parameter? It DID work as a subclass...

    Code:
    CallBack Function KeyboardCallBack() As Long
    Local St      As String
    Select Case CbMsg
        Case %WM_KEYUP
             Control Get Text CbHndl, %IDTEXT2 To St
             If St = "PASSWORD" Then Control Enable CbHndl,%IDBUTTON2
    End Select
    End Function
    ------------------
    Scott
    mailto:[email protected][email protected]</A>
Working...
X