Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Use OOP for your DDT forms

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

  • PBWin Use OOP for your DDT forms

    Here is something which can be so handy for your programming.
    Attach an interface to your DDT form.

    The DDTForm_CreateObject macro is used to create the object and attach it to a form.
    You can use the iForm variable right away.

    If you use this macro you must release the object when the form terminates, use the DDTForm_DestroyObject macro in the WM_DESTROY to do so.

    If you need the object, you should obtain it during the message.
    You can use the DDTForm_GetObject macro to obtain a reference.
    Important to understand the reference is lost when the message is done
    Don't try to make it static bu use this macro during each message where you need the object.
    This is shown in the small example below.

    Code:
    ' Place this in WM_INITDIALOG
    Macro DDTForm_CreateObject
        Local iForm As IDDTForm
        iForm = Class "clsDDTForm"
        iForm.BackDoor.hWnd = CbHndl
        Call SetProp( CbHndl, "IDDTForm", ObjPtr( iForm ) )
        iForm.Addref()
    End Macro
    
    ' Place this in WM_DESTROY
    Macro DDTForm_DestroyObject
        iForm = Nothing
        Poke Dword, VarPtr( iForm ), GetProp( CbHndl, "IDDTForm" )
        RemoveProp( CbHndl, "IDDTForm" )
    End Macro
    
    ' Place this in each occasion you need the object.
    Macro DDTForm_GetObject
        iForm = Nothing
        Poke Dword, VarPtr( iForm ), GetProp( CbHndl, "IDDTForm" )
        iForm.Addref()
    End Macro
    
    Class clsDDTForm
    
        Instance m_hWnd As Long
    
        Class Method Create
        End Method
    
        Class Method Destroy
        End Method
    
        Interface IDDTForm: Inherit IUnknown
    
            Property Get BackDoor As DDTForm_IBackDoor
                Property = Me
            End Property
    
            Property Get Text() As String
                Local T As String
                Dialog Get Text m_hWnd To T
                Property = T
            End Property
    
            Property Set Text( ByVal value As String )
                Dialog Set Text m_hWnd, value
            End Property
    
            Property Get Enable() As Long
                Property = IsWindowEnabled( m_hWnd )
            End Property
    
            Property Set Enable( ByVal value As Long )
                EnableWindow( m_hWnd, value )
            End Property
    
        End Interface
    
        Interface DDTForm_IBackDoor: Inherit IUnknown
    
            Property Set hWnd( ByVal value As Long )
                m_hWnd = value
            End Property
    
        End Interface
    
    End Class
    The following code is the content of dialog callback procedure, it shows how you can extend the DDT form with an object.
    Code:
        Select Case nCbMsg
        Case %WM_INITDIALOG
        
            DDTForm_CreateObject
            iForm.Text = Time$
        
        Case %WM_COMMAND
    
            Select Case CbCtl
            Case %IDOK
    
                Select Case CbCtlMsg
                Case %BN_CLICKED                
                    
                    DDTForm_GetObject
                    MsgBox iForm.Text & " - OK", %MB_TASKMODAL, "OOP"
    
                End Select
    
            Case %IDCANCEL
    
                Select Case CbCtlMsg
                Case %BN_CLICKED
    
                    DDTForm_GetObject
                    MsgBox iForm.Text & " - Cancel", %MB_TASKMODAL, "OOP"
    
                End Select
    
            End Select
    
        Case %WM_DESTROY
            DDTForm_DestroyObject
        End Select
    Last edited by Edwin Knoppert; 4 Aug 2009, 11:05 AM.
    hellobasic
Working...
X