• Welcome to Theos PowerBasic Museum 2017.

What can I subclass in PB9 CLASS ?

Started by Weihong Zhen, October 09, 2008, 04:13:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Weihong Zhen

I tried, and failed!  :'(

The following are my examples of the types of


#Compile Exe
#Dim All

#Include "Win32API.inc"

%ID_TextBox1    = 100
%ID_LABEL1      = 101

Global TextBox1 As ITextBox,TextHwnd As Long , hDlg As Long

Function PBMain () As Long

Dialog New 0, "clsTextBox examples", 152, 15, 144, 57, %ws_popup Or _
        %ws_border Or %ws_dlgframe Or %ws_caption Or %ws_sysmenu Or _
        %ws_minimizebox Or %ws_clipsiblings Or %ws_visible Or %ds_modalframe _
        Or %ds_3dlook Or %ds_nofailcreate Or %ds_setfont, _
        %ws_ex_controlparent Or %ws_ex_left Or %ws_ex_ltrreading Or _
        %ws_ex_rightscrollbar, To hDlg

  Control Add Label, hDlg, %ID_LABEL1, "MaxLength=2 AND 10+10 ", 6, 10, 100, 12
  Control Add TextBox, hDlg, %ID_TextBox1, "", 6, 20, 100, 12

  Control Handle hDlg, %ID_TextBox1 To TextHwnd

  Dialog Show Modal hDlg Call DlgProc 'To Result
End Function


CallBack Function DlgProc( ) As Long
    Select Case Cb.Msg
            Case %wm_initdialog
                Set TextBox1 = Class "clsTextBox"
                TextBox1.hWnd =TextHwnd
                TextBox1.Enable = 1
                TextBox1.MaxLength=2

                Control Set Text hDlg, %ID_TextBox1,Str$(TEXTBOX1.BumpIt(10))

    End Select
End Function

Class clsTextBox

    Instance m_hWnd As Long
    Class Method Create
        '
    End Method

    Class Method Destroy
        '
    End Method


    Interface ITextBox: Inherit IUnknown

        Property Get hWnd() As Long
            Property = m_hWnd
        End Property

        Property Set hWnd( ByVal hWnd As Long )
            m_hWnd = hWnd
        End Property

        Property Get Enable() As Long
            Property = IsWindowEnabled( m_hWnd )
        End Property

        Property Set Enable( ByVal fEnable As Long )
            EnableWindow( m_hWnd, fEnable )
        End Property

        Property Get MaxLength() As Long
            Property = SendMessage( m_hWnd, %EM_GETLIMITTEXT, 0, ByVal 0& )
        End Property

        Property Set MaxLength( ByVal cbMax As Long )
            SendMessage( m_hWnd, %EM_SETLIMITTEXT, cbMax, ByVal 0& )
        End Property

        Method BumpIt(Inc As Long) As Long
         
          Method=INC+INC
        End Method

       'What can I subclass in PB9 CLASS ?
    End Interface

End Class


José Roca

 
I'm not certain of what you're trying to do. You are calling Control Set Text hDlg, %ID_TextBox1,Str$(TEXTBOX1.BumpIt(10)) and it is printing 20, because the method BumpIt just adds 10+10 (Method=INC+INC).

If you want to see 22 then change the code as follows:


        Method BumpIt(Inc As Long) As Long
          Method = ME.MaxLength+INC+INC
        End Method