Microsoft Chat Server Development Guide |
---|
' This property page is called from the ChannelBlocking extension sample.
' Using the chat object model, it retrieves a reference to the instance
' of the extension running on the machine currently being configured.
' Using the reference to the extension, it calls methods/properties
' implemented by the extension to edit the work list held by the extension
' You should always require explicitly declared variables
Option Explicit
' The listbox.itemdata holds a flag to indicate
' whether the word was added during this edit
Const NEWNAME = 0
Const OLDNAME = 1
' A collection of names to be deleted from the list when changes are applies
Dim gDeletedNames As Collection
' interface to our running extension on the chat server
Dim gBlockSvr As ChannelBlockExtension.ChannelBlocking
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Initialize/free our global variables when the property page is initialize/terminated
''
Private Sub PropertyPage_Initialize()
Set gDeletedNames = New Collection
End Sub
Private Sub PropertyPage_Terminate()
Set gDeletedNames = Nothing
Set gBlockSvr = Nothing
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Routine that fills in our list box from the names already held by the extension
Private Sub FillNameList()
lstNames.Clear
If Not gBlockSvr Is Nothing Then
Dim s As Variant
For Each s In gBlockSvr ' Add name to list, set ItemData to indicate its original
lstNames.AddItem UCase(s)
lstNames.ItemData(lstNames.NewIndex) = OLDNAME
Next
End If
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This property page method is called when either Apply or OK is pressed
' It then modifies the list held by the server, with the data held here
Private Sub PropertyPage_ApplyChanges()
' Add names from the listbox whose itemdata are marked as NEWNAME
Dim i As Integer
For i = 0 To lstNames.ListCount - 1
If lstNames.ItemData(i) = NEWNAME Then
gBlockSvr.Add (lstNames.List(i))
End If
Next
' Remove names from the extensions list that were deleted
' and remove them from our collection
With gDeletedNames
While .Count > 0
gBlockSvr.Remove CStr(.Item(1)) ' Remove the word from the extensions
.Remove (1) ' and remove it from our copy
Wend
End With
' Refresh our listbox with the names stored by the server
Call FillNameList
Changed = False
End Sub
' This PropertyPage method is called when you need to fill in the properties
Private Sub PropertyPage_SelectionChanged()
Dim CServer As CHATSVCLib.ChatServer
' Set the commands enables
cmdAdd.Enabled = False
cmdDelete.Enabled = False
If SelectedControls.Count > 0 Then
' We are passed a reference to the ChatServer object by SelectedControls(0)
Set CServer = SelectedControls(0)
If Not CServer Is Nothing Then
Set gBlockSvr = CServer.Configuration.ChatExtensions("ChannelBlocking").Instance
If Not gBlockSvr Is Nothing Then
Call FillNameList
End If
End If
End If
End Sub
' The user has clicked on a names in the listbox
Private Sub lstNames_Click()
txtName = lstNames.List(lstNames.ListIndex)
End Sub
' Whenever the Name text field changes, set the Add/Delete buttons
' to a valid setting on whether the name already exists or not
Private Sub txtName_Change()
' Assume this is a new entry
cmdAdd.Enabled = True
cmdDelete.Enabled = False
' then search what names we have already
Dim i As Integer
For i = 0 To lstNames.ListCount - 1
If lstNames.List(i) = txtName Then ' we already have this name
' so set controls to allow us to delete it
cmdAdd.Enabled = False
cmdDelete.Enabled = True
Exit Sub
End If
Next
End Sub
' User has clicked on the Add Name button
Private Sub cmdAdd_Click()
' Add name to listbox, and mark as a NEWNAME
lstNames.AddItem UCase(txtName)
lstNames.ItemData(lstNames.NewIndex) = NEWNAME
lstNames.ListIndex = lstNames.NewIndex
cmdAdd.Enabled = False ' Can't add it twice
Changed = True ' Enable PPage's Apply button
End Sub
' User has clicked on the DeleteName button
Private Sub cmdDelete_Click()
On Error Resume Next ' ignore errors if the name is already entered for removal
gDeletedNames.Add txtName
lstNames.RemoveItem lstNames.ListIndex
On Error GoTo 0
cmdDelete.Enabled = False ' Can't delete it twice
Changed = True ' enable PPage's Apply button
End Sub
© 1998 Microsoft Corporation. All rights reserved.