Announcement

Collapse
No announcement yet.

Subclassing DDT

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

  • 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

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

    Regards,
    Adam

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

    Comment


    • #3
      Adam
      Where did you locate Lance's example? I cannot find it.

      Bruce



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

      Comment


      • #4
        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).]

        Comment


        • #5
          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.


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

          Comment


          • #6
            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

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

            Comment


            • #7
              Thanks Adam & Seman

              This should do it. Thanks again

              Bruce


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

              Comment


              • #8
                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


                Scott Turchin
                MCSE, MCP+I
                http://www.tngbbs.com
                ----------------------
                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                Comment

                Working...
                X