Announcement

Collapse
No announcement yet.

Subclassing DDT

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

  • Scott Turchin
    replied
    Here's my sample of how to subclass an edit control so that only the letters A-F and 0-9 may appear. (representing Hex values of course!)

    Code:
    'Create a DDT edit box, labeled %IDTEXT1
    'In main dialog procedure:
        Case %WM_INITDIALOG
             ' Subclass the edit control
             Control Handle CbHndl, %IDTEXT1 To hEdit&
             gOldSubClassProc = SetWindowLong(hEdit&, %GWL_WNDPROC, CodePtr(SubClassProc))  
    
    
        Case %WM_DESTROY
          ' Important! Remove the subclassing
          SetWindowLong hEdit&, %GWL_WNDPROC, gOldSubClassProc
          Function = 0
          Exit Function
    
    'Now the subclass procedure:
    'Not 100% sure this is all accurate, but it does work...:-)
    
    '------------------------------------------------------------
    Function SubClassProc(ByVal hWnd&, ByVal wMsg&, ByVal wParam&, ByVal lParam&) As Long
        Local NewChar As Asciiz * 2
        Local Y       As Long
        Local zText   As Asciiz * 13
        Local yMsg    As Long
    ' Process our messages in this subclass procedure
    Select Case wMsg&
        Case %WM_KEYDOWN
             yMsg = LoWrd(wParam&) 'Actual ascii value of keystroke coming in
             Select Case yMsg
             Case 8,48 To 57, 65 To 70, 97 To 102
                ' do nothing
             Case 35,36,37,39,40,46
                ' do nothing
    '     Left arrow = 37
    '     Right arrow = 39
    '     home = 36
    '     Down = 40
    '     Up = 38
    '     End = 35
             Case Else
                Function = %NULL
                Exit Function
             End Select
        Case %WM_CHAR
             yMsg = LoWrd(wParam&) 'Actual ascii value of keystroke coming in
             Select Case yMsg
             Case 8 'BackSpace
             Case 48 To 57 ,65 To 70
             Case 97 To 102 'a-f
             Case Else
                 Function = %NULL
                 Exit Function
             End Select
    
        Case %WM_KEYUP
             Control Get Text hDlg, %IDTEXT1 To St
             If Len(St) = 12  Then
                Control Enable hDlg, %IDSWAP
             Else
                Control Disable hDlg, %IDSWAP
             End If
    End Select
    ' Pass the message on to the original window procedure... the DDT engine!
    Function = CallWindowProc(gOldSubClassProc, hWnd&, wMsg&, wParam&, lParam&)
    End Function
    '-------------------------------------------------------------------------------

    ------------------
    Scott Turchin


    Leave a comment:


  • Bruce Singleton
    replied
    Thanks Adam & Seman

    This should do it. Thanks again

    Bruce


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

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Semen,
    It is still a good example of subclassing in general and that is what I wanted. I had already investigated that link before I checked out Lance's example. I have been able to adapt it to work with any control I need it for. It depends on what Bruce wants to do - subcalss the whole window or just a control(s). I haven't tried it on the whole window yet(at this point I don't need to).

    Regards,
    Adam

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

    Leave a comment:


  • Semen Matusovski
    replied
    as i remember, lance' sample is for subclassing alone edit control.
    if you want to subclass whole ddt' window, look http://www.powerbasic.com/support/pb...ad.php?t=12662
    up to now, lance didn't post information that it's not correct to replace dialog doevents by described way.


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

    Leave a comment:


  • Guest's Avatar
    Guest replied
    hi bruce,
    i had to dig way back for this:

    it's a pretty straight forward example and i had no problem adapting it to fit my needs. have fun.

    regards,
    adam

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




    [this message has been edited by adam ritchie (edited february 23, 2000).]

    Leave a comment:


  • Bruce Singleton
    replied
    Adam
    Where did you locate Lance's example? I cannot find it.

    Bruce



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

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Never mind y'all, I found Lance's example on subclassing an edit control in a ddt window.

    Regards,
    Adam

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

    Leave a comment:


  • Guest's Avatar
    Guest started a topic Subclassing DDT

    Subclassing DDT

    I know there was an example or article posted sometime ago about subclassing and I would like to learn how to do it. I looked for it earlier but wasn't able to find it. Maybe I didn't go far enough back. I want to just simply learn how to subclass ddt controls in general. If someone knows the url for that,would you be so kind as to let me know what that is?

    Thanks,
    Adam
Working...
X