home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectPlay / DXVBMessenger / Client / frmClient.frm (.txt) next >
Encoding:
Visual Basic Form  |  2001-10-08  |  21.0 KB  |  532 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form frmClient 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "vbMessenger Service (Not logged in)"
  6.    ClientHeight    =   4740
  7.    ClientLeft      =   150
  8.    ClientTop       =   720
  9.    ClientWidth     =   4170
  10.    Icon            =   "frmClient.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   4740
  15.    ScaleWidth      =   4170
  16.    StartUpPosition =   3  'Windows Default
  17.    Begin VB.Timer tmrUpdate 
  18.       Enabled         =   0   'False
  19.       Interval        =   50
  20.       Left            =   4650
  21.       Top             =   2700
  22.    End
  23.    Begin VB.Timer tmrExit 
  24.       Interval        =   50
  25.       Left            =   8100
  26.       Top             =   840
  27.    End
  28.    Begin MSComctlLib.ImageList imlTree 
  29.       Left            =   4680
  30.       Top             =   1140
  31.       _ExtentX        =   1005
  32.       _ExtentY        =   1005
  33.       BackColor       =   -2147483643
  34.       ImageWidth      =   16
  35.       ImageHeight     =   16
  36.       MaskColor       =   12632256
  37.       _Version        =   393216
  38.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  39.          NumListImages   =   2
  40.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  41.             Picture         =   "frmClient.frx":030A
  42.             Key             =   ""
  43.          EndProperty
  44.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  45.             Picture         =   "frmClient.frx":0C34
  46.             Key             =   ""
  47.          EndProperty
  48.       EndProperty
  49.    End
  50.    Begin MSComctlLib.TreeView tvwFriends 
  51.       Height          =   4695
  52.       Left            =   0
  53.       TabIndex        =   0
  54.       Top             =   0
  55.       Width           =   4155
  56.       _ExtentX        =   7329
  57.       _ExtentY        =   8281
  58.       _Version        =   393217
  59.       Indentation     =   88
  60.       LabelEdit       =   1
  61.       Style           =   7
  62.       ImageList       =   "imlTree"
  63.       Appearance      =   1
  64.    End
  65.    Begin VB.Menu mnuFile 
  66.       Caption         =   "&File"
  67.       Begin VB.Menu mnuLogon 
  68.          Caption         =   "&Log on..."
  69.          Shortcut        =   ^L
  70.       End
  71.       Begin VB.Menu mnuLogoff 
  72.          Caption         =   "Lo&g Off"
  73.          Shortcut        =   ^X
  74.       End
  75.       Begin VB.Menu mnuSep 
  76.          Caption         =   "-"
  77.       End
  78.       Begin VB.Menu mnuExit 
  79.          Caption         =   "E&xit"
  80.       End
  81.    End
  82.    Begin VB.Menu mnuOptions 
  83.       Caption         =   "&Options"
  84.       Begin VB.Menu mnuAddFriend 
  85.          Caption         =   "&Add Friend..."
  86.          Shortcut        =   ^A
  87.       End
  88.       Begin VB.Menu mnuBlock 
  89.          Caption         =   "&Block User..."
  90.          Shortcut        =   ^B
  91.       End
  92.       Begin VB.Menu mnuSep1 
  93.          Caption         =   "-"
  94.       End
  95.       Begin VB.Menu mnuSendIM 
  96.          Caption         =   "&Send Message..."
  97.          Shortcut        =   ^S
  98.       End
  99.    End
  100.    Begin VB.Menu mnuPop 
  101.       Caption         =   "pop"
  102.       Visible         =   0   'False
  103.       Begin VB.Menu mnuSend 
  104.          Caption         =   "Send Message"
  105.       End
  106.    End
  107.    Begin VB.Menu mnuPopTray 
  108.       Caption         =   "pop2"
  109.       Visible         =   0   'False
  110.       Begin VB.Menu mnuExitTray 
  111.          Caption         =   "E&xit"
  112.       End
  113.    End
  114. Attribute VB_Name = "frmClient"
  115. Attribute VB_GlobalNameSpace = False
  116. Attribute VB_Creatable = False
  117. Attribute VB_PredeclaredId = True
  118. Attribute VB_Exposed = False
  119. Option Explicit
  120. Option Compare Text
  121. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  122. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  123. '  File:       frmClient.frm
  124. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  125. Implements DirectPlay8Event
  126. Private Const msAppTitle As String = "vbMessenger Service"
  127. Private mfExit As Boolean
  128. Private oLog As frmLogin
  129. Private oLeafOnline As Node
  130. Private oLeafOffline As Node
  131. Private oMsgWnd() As frmMsgTemplate
  132. Private mfServerExit As Boolean
  133. Private Sub Form_Load()
  134.     'Initialize DirectPlay
  135.     Set gofrmClient = Me
  136.     InitDPlay
  137.     'Lets put an icon in the system tray
  138.     With sysIcon
  139.         .cbSize = LenB(sysIcon)
  140.         .hwnd = Me.hwnd
  141.         .uFlags = NIF_DOALL
  142.         .uCallbackMessage = WM_MOUSEMOVE
  143.         .hIcon = Me.Icon
  144.         .sTip = msAppTitle & " - Not logged in." & vbNullChar
  145.     End With
  146.     Shell_NotifyIcon NIM_ADD, sysIcon
  147.     SetupDefaultTree
  148.     EnableLoggedinUI False
  149.     EnableSendUI False
  150.     Me.Caption = msAppTitle & " - Not logged in."
  151. End Sub
  152. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  153.     Dim ShellMsg As Long
  154.     ShellMsg = X / Screen.TwipsPerPixelX
  155.     Select Case ShellMsg
  156.     Case WM_LBUTTONDBLCLK
  157.         Me.Visible = True
  158.         Me.SetFocus
  159.     Case WM_RBUTTONUP
  160.         PopupMenu mnuPopTray
  161.     End Select
  162. End Sub
  163. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  164.     If Not mfExit Then
  165.         Cancel = 1
  166.         Me.Hide
  167.     End If
  168. End Sub
  169. Private Sub Form_Unload(Cancel As Integer)
  170.     Dim lCount As Long
  171.     'Cleanup the DPlay objects
  172.     Cleanup
  173.     'Remove all the forms
  174.     On Error Resume Next
  175.     Dim lNum As Long
  176.     lNum = UBound(oMsgWnd)
  177.     For lCount = 0 To lNum
  178.         Unload oMsgWnd(lCount)
  179.         Set oMsgWnd(lCount) = Nothing
  180.     Next
  181.     Erase oMsgWnd
  182.     'Remove the icon from the system tray
  183.     Shell_NotifyIcon NIM_DELETE, sysIcon
  184. End Sub
  185. Private Sub mnuAddFriend_Click()
  186.     'Let's get the name of the friend we want to add
  187.     Dim sFriend As String
  188.     sFriend = InputBox("Please enter the name of the friend you wish to add", "Add Friend")
  189.     If sFriend = vbNullString Then
  190.         'nothing was entered
  191.         MsgBox "You must enter a friends name to add one.", vbOKOnly Or vbInformation, "Nothing entered."
  192.         Exit Sub
  193.     ElseIf sFriend = gsUserName Then
  194.         'Entered our own name
  195.         MsgBox "Everyone wants to be friends with themselves, but in this sample, it's not allowed.", vbOKOnly Or vbInformation, "Don't enter your name."
  196.         Exit Sub
  197.     End If
  198.     'Ok, let's add the friend
  199.     AddFriend sFriend
  200. End Sub
  201. Private Sub mnuBlock_Click()
  202.     'Let's get the name of the friend we want to block
  203.     Dim sFriend As String
  204.     sFriend = InputBox("Please enter the name of the user you wish to block", "Block user")
  205.     If sFriend = vbNullString Then
  206.         'nothing was entered
  207.         MsgBox "You must enter a user name to block one.", vbOKOnly Or vbInformation, "Nothing entered."
  208.         Exit Sub
  209.     ElseIf sFriend = gsUserName Then
  210.         'Entered our own name
  211.         MsgBox "Why would you want to block yourself?.", vbOKOnly Or vbInformation, "Don't enter your name."
  212.         Exit Sub
  213.     End If
  214.     'Ok, let's add the friend
  215.     BlockUser sFriend
  216. End Sub
  217. Private Sub mnuExit_Click()
  218.     mfExit = True
  219.     Unload Me
  220. End Sub
  221. Private Sub mnuExitTray_Click()
  222.     mnuExit_Click
  223. End Sub
  224. Private Sub mnuLogoff_Click()
  225.     EnableLoggedinUI False
  226.     gfConnected = False
  227.     gfCreatePlayer = False
  228.     gfLoggedIn = False
  229.     gsUserName = vbNullString
  230.     gsPass = vbNullString
  231.     gsServerName = vbNullString
  232.     Me.Caption = "vbMessenger Service (Not logged in)"
  233.     UpdateText "vbMessenger Service (Not logged in)"
  234.     SetupDefaultTree
  235.     'Initialize DirectPlay
  236.     InitDPlay
  237. End Sub
  238. Private Sub mnuLogon_Click()
  239.     'They want to log on, show the logon screen
  240.     Set oLog = New frmLogin
  241.     oLog.Show , Me
  242. End Sub
  243. Private Sub EnableLoggedinUI(ByVal fEnable As Boolean)
  244.     mnuAddFriend.Enabled = fEnable
  245.     mnuBlock.Enabled = fEnable
  246.     mnuLogoff.Enabled = fEnable
  247.     mnuLogon.Enabled = Not fEnable
  248. End Sub
  249. Private Sub EnableSendUI(ByVal fEnable As Boolean)
  250.     mnuSend.Enabled = fEnable
  251.     mnuSendIM.Enabled = fEnable
  252. End Sub
  253. Private Sub mnuSend_Click()
  254.     mnuSendIM_Click 'Go ahead and send a message
  255. End Sub
  256. Private Sub mnuSendIM_Click()
  257.     Dim frm As frmMsgTemplate
  258.     If InStr(tvwFriends.SelectedItem.Text, " ") > 0 Then
  259.         Set frm = GetMsgWindow(Left$(tvwFriends.SelectedItem.Text, InStr(tvwFriends.SelectedItem.Text, " ") - 1))
  260.         frm.UserName = Left$(tvwFriends.SelectedItem.Text, InStr(tvwFriends.SelectedItem.Text, " ") - 1)
  261.     Else
  262.         Set frm = GetMsgWindow(tvwFriends.SelectedItem.Text)
  263.         frm.UserName = tvwFriends.SelectedItem.Text
  264.     End If
  265.     frm.Show
  266.     frm.SetFocus
  267. End Sub
  268. Private Sub tmrExit_Timer()
  269.     If mfServerExit Then 'Gotta quit now
  270.         tmrExit.Enabled = False
  271.         MsgBox "The server has disconnected.  This session will now end.", vbOKOnly Or vbInformation, "Exiting..."
  272.         mfExit = True
  273.         Unload Me
  274.         End
  275.     End If
  276. End Sub
  277. Private Sub tmrUpdate_Timer()
  278.     tmrUpdate.Enabled = False
  279.     If gfCreatePlayer Then
  280.         CreatePlayer 'We're creating a player
  281.     Else
  282.         LogonPlayer 'We're just logging in
  283.     End If
  284. End Sub
  285. Private Sub tvwFriends_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  286.     Dim oNode As Node
  287.     If Button = vbRightButton Then 'They right clicked, should we show the menu?
  288.         If tvwFriends.SelectedItem.Parent Is Nothing Then
  289.             Set oNode = oLeafOffline
  290.         Else
  291.             Set oNode = tvwFriends.SelectedItem
  292.         End If
  293.         If (oNode.Children = 0) And oNode <> oLeafOffline Then
  294.             PopupMenu mnuPop
  295.         End If
  296.     End If
  297. End Sub
  298. Private Sub tvwFriends_NodeClick(ByVal Node As MSComctlLib.Node)
  299.     Dim oNode As Node
  300.     If Node.Parent Is Nothing Then
  301.         Set oNode = oLeafOffline
  302.     Else
  303.         Set oNode = Node
  304.     End If
  305.     If (oNode.Children = 0) And oNode <> oLeafOffline Then
  306.         EnableSendUI True
  307.     Else
  308.         EnableSendUI False
  309.     End If
  310. End Sub
  311. Private Sub UpdateText(sNewText As String)
  312.     'modify our icon text
  313.     sysIcon.sTip = sNewText & vbNullChar
  314.     sysIcon.uFlags = NIF_TIP
  315.     Shell_NotifyIcon NIM_MODIFY, sysIcon
  316. End Sub
  317. Private Function GetMsgWindow(ByVal sUser As String) As frmMsgTemplate
  318.     'Let's check to see if there is a window open
  319.     Dim lCount As Long, lNumWindows As Long
  320.     On Error Resume Next
  321.     lNumWindows = UBound(oMsgWnd)
  322.     If Err = 0 Then
  323.         For lCount = 0 To lNumWindows
  324.             If Not (oMsgWnd(lCount) Is Nothing) Then
  325.                 If sUser = oMsgWnd(lCount).UserName Then
  326.                     Set GetMsgWindow = oMsgWnd(lCount)
  327.                     Exit Function
  328.                 End If
  329.             End If
  330.         Next
  331.         ReDim Preserve oMsgWnd(lNumWindows + 1)
  332.         Set oMsgWnd(lNumWindows + 1) = New frmMsgTemplate
  333.         Set GetMsgWindow = oMsgWnd(lNumWindows + 1)
  334.     Else
  335.         ReDim oMsgWnd(0)
  336.         Set oMsgWnd(0) = New frmMsgTemplate
  337.         Set GetMsgWindow = oMsgWnd(0)
  338.     End If
  339.         
  340. End Function
  341. Private Sub SetupDefaultTree()
  342.     'Clear the tree first
  343.     tvwFriends.Nodes.Clear
  344.     'Let's add the two default icons into our treeview
  345.     Set oLeafOnline = tvwFriends.Nodes.Add(, , "OnlineLeafKey", "Friends online", 1, 1)
  346.     Set oLeafOffline = tvwFriends.Nodes.Add(, , "OfflineLeafKey", "Friends offline", 2, 2)
  347. End Sub
  348. Private Sub DirectPlay8Event_AddRemovePlayerGroup(ByVal lMsgID As Long, ByVal lPlayerID As Long, ByVal lGroupID As Long, fRejectMsg As Boolean)
  349.     'VB requires that we must implement *every* member of this interface
  350. End Sub
  351. Private Sub DirectPlay8Event_AppDesc(fRejectMsg As Boolean)
  352.     'VB requires that we must implement *every* member of this interface
  353. End Sub
  354. Private Sub DirectPlay8Event_AsyncOpComplete(dpnotify As DxVBLibA.DPNMSG_ASYNC_OP_COMPLETE, fRejectMsg As Boolean)
  355.     'VB requires that we must implement *every* member of this interface
  356. End Sub
  357. Private Sub DirectPlay8Event_ConnectComplete(dpnotify As DxVBLibA.DPNMSG_CONNECT_COMPLETE, fRejectMsg As Boolean)
  358.     If dpnotify.hResultCode <> 0 Then
  359.         MsgBox "The server does not exist or is unavailable.", vbOKOnly Or vbInformation, "Unavailable"
  360.     Else
  361.         tmrUpdate.Enabled = True
  362.     End If
  363.     gfConnected = True
  364. End Sub
  365. Private Sub DirectPlay8Event_CreateGroup(ByVal lGroupID As Long, ByVal lOwnerID As Long, fRejectMsg As Boolean)
  366.     'VB requires that we must implement *every* member of this interface
  367. End Sub
  368. Private Sub DirectPlay8Event_CreatePlayer(ByVal lPlayerID As Long, fRejectMsg As Boolean)
  369.     'VB requires that we must implement *every* member of this interface
  370. End Sub
  371. Private Sub DirectPlay8Event_DestroyGroup(ByVal lGroupID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  372.     'VB requires that we must implement *every* member of this interface
  373. End Sub
  374. Private Sub DirectPlay8Event_DestroyPlayer(ByVal lPlayerID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  375.     'VB requires that we must implement *every* member of this interface
  376. End Sub
  377. Private Sub DirectPlay8Event_EnumHostsQuery(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_QUERY, fRejectMsg As Boolean)
  378.     'VB requires that we must implement *every* member of this interface
  379. End Sub
  380. Private Sub DirectPlay8Event_EnumHostsResponse(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_RESPONSE, fRejectMsg As Boolean)
  381.     'VB requires that we must implement *every* member of this interface
  382. End Sub
  383. Private Sub DirectPlay8Event_HostMigrate(ByVal lNewHostID As Long, fRejectMsg As Boolean)
  384.     'VB requires that we must implement *every* member of this interface
  385. End Sub
  386. Private Sub DirectPlay8Event_IndicateConnect(dpnotify As DxVBLibA.DPNMSG_INDICATE_CONNECT, fRejectMsg As Boolean)
  387.     'VB requires that we must implement *every* member of this interface
  388. End Sub
  389. Private Sub DirectPlay8Event_IndicatedConnectAborted(fRejectMsg As Boolean)
  390.     'VB requires that we must implement *every* member of this interface
  391. End Sub
  392. Private Sub DirectPlay8Event_InfoNotify(ByVal lMsgID As Long, ByVal lNotifyID As Long, fRejectMsg As Boolean)
  393.     'VB requires that we must implement *every* member of this interface
  394. End Sub
  395. Private Sub DirectPlay8Event_Receive(dpnotify As DxVBLibA.DPNMSG_RECEIVE, fRejectMsg As Boolean)
  396.     'We need to get each message we receive from the server, process it, and respond accordingly
  397.     Dim lMsg As Long, lOffset As Long
  398.     Dim oNewMsg() As Byte, lNewOffSet As Long
  399.     Dim sUsername As String, lNumFriends As Long, lCount As Long
  400.     Dim lNewMsg As Long, oNode As Node
  401.     Dim sChat As String, fChatFrm As frmMsgTemplate
  402.     Dim fFriend As Boolean, fFound As Boolean
  403.     With dpnotify
  404.     GetDataFromBuffer .ReceivedData, lMsg, LenB(lMsg), lOffset
  405.     Select Case lMsg 'The client will only receive certain messages.  Handle those.
  406.     Case Msg_LoginSuccess 'Login successfully completed.
  407.         'All we really need to do is get rid of the login screen.
  408.         If Not (oLog Is Nothing) Then
  409.             Unload oLog
  410.             Set oLog = Nothing
  411.         End If
  412.         Unload frmCreate
  413.         gfLoggedIn = True
  414.         EnableLoggedinUI True
  415.         Me.Caption = msAppTitle & " - (" & gsUserName & ")"
  416.         UpdateText msAppTitle & " - (" & gsUserName & ")"
  417.     Case Msg_InvalidPassword 'The server didn't like our password
  418.         'The password they entered was invalid.
  419.         MsgBox "The password you entered was invalid.", vbOKOnly Or vbInformation, "Not valid."
  420.         oLog.cmdLogin.Enabled = True
  421.         oLog.txtPassword = vbNullString
  422.         oLog.txtPassword.SetFocus
  423.     Case Msg_InvalidUser 'We do not exist on this server
  424.         'This user does not exist
  425.         MsgBox "The username you entered does not exist.", vbOKOnly Or vbInformation, "Not valid."
  426.         oLog.cmdLogin.Enabled = True
  427.     Case Msg_UserAlreadyExists 'We can't create this account since the user exists
  428.         'This user already exists
  429.         MsgBox "The username you entered already exists." & vbCrLf & "You must choose a different one.", vbOKOnly Or vbInformation, "Not valid."
  430.         frmCreate.cmdLogin.Enabled = True
  431.     Case Msg_SendClientFriends 'The server is going to send us a list of our current friends
  432.         GetDataFromBuffer .ReceivedData, lNumFriends, LenB(lNumFriends), lOffset
  433.         'Ok, now go through and add each friend to our 'offline' list (The server will notify who is online after this message
  434.         For lCount = 1 To lNumFriends
  435.             GetDataFromBuffer .ReceivedData, fFriend, LenB(fFriend), lOffset
  436.             sUsername = GetStringFromBuffer(.ReceivedData, lOffset)
  437.             'Add this user to our list
  438.             If fFriend Then
  439.                 tvwFriends.Nodes.Add oLeafOffline, tvwChild, sUsername, sUsername, 2, 2
  440.             Else
  441.                 tvwFriends.Nodes.Add oLeafOffline, tvwChild, sUsername, sUsername & " (BLOCKED)", 2, 2
  442.             End If
  443.         Next
  444.         oLeafOffline.Expanded = True
  445.         oLeafOnline.Expanded = True
  446.     Case Msg_FriendAdded
  447.         sUsername = GetStringFromBuffer(.ReceivedData, lOffset)
  448.         fFound = False
  449.         For Each oNode In tvwFriends.Nodes
  450.             If oNode.Key = sUsername Then
  451.                 oNode.Text = sUsername
  452.                 fFound = True
  453.             End If
  454.         Next
  455.         If Not fFound Then tvwFriends.Nodes.Add oLeafOffline, tvwChild, sUsername, sUsername, 2, 2
  456.         'Friend added successfully
  457.         MsgBox sUsername & " added successfully to your friends list.", vbOKOnly Or vbInformation, "Added."
  458.     Case Msg_FriendBlocked
  459.         sUsername = GetStringFromBuffer(.ReceivedData, lOffset)
  460.         fFound = False
  461.         For Each oNode In tvwFriends.Nodes
  462.             If oNode.Key = sUsername Then
  463.                 oNode.Text = sUsername & " (BLOCKED)"
  464.                 fFound = True
  465.             End If
  466.         Next
  467.         If Not fFound Then tvwFriends.Nodes.Add oLeafOffline, tvwChild, sUsername, sUsername & " (BLOCKED)", 2, 2
  468.         'Friend blocked successfully
  469.         MsgBox sUsername & " added successfully to your blocked list.", vbOKOnly Or vbInformation, "Added."
  470.             
  471.     Case Msg_FriendDoesNotExist
  472.         'Friend doesn't exist
  473.         MsgBox "You cannot add this friend, since they do not exist.", vbOKOnly Or vbInformation, "Unknown."
  474.     Case Msg_BlockUserDoesNotExist
  475.         'Friend doesn't exist
  476.         MsgBox "You cannot block this user, since they do not exist.", vbOKOnly Or vbInformation, "Unknown."
  477.         
  478.     Case Msg_FriendLogon
  479.         'We need to go through each of the current nodes and see if this is that friend
  480.         sUsername = GetStringFromBuffer(.ReceivedData, lOffset)
  481.         For Each oNode In tvwFriends.Nodes
  482.             If oNode.Key = sUsername And oNode.Children = 0 Then
  483.                 oNode.Image = 1: oNode.SelectedImage = 1
  484.                 Set oNode.Parent = oLeafOnline
  485.             End If
  486.         Next
  487.     Case Msg_FriendLogoff
  488.         'We need to go through each of the current nodes and see if this is that friend
  489.         sUsername = GetStringFromBuffer(.ReceivedData, lOffset)
  490.         For Each oNode In tvwFriends.Nodes
  491.             If oNode.Key = sUsername And oNode.Children = 0 Then
  492.                 oNode.Image = 2: oNode.SelectedImage = 2
  493.                 Set oNode.Parent = oLeafOffline
  494.             End If
  495.         Next
  496.     Case Msg_ReceiveMessage
  497.         'We need to go through each of the current forms and see if this is friend is loaded
  498.         sUsername = GetStringFromBuffer(.ReceivedData, lOffset)
  499.         sChat = GetStringFromBuffer(.ReceivedData, lOffset)
  500.         Set fChatFrm = GetMsgWindow(sUsername)
  501.         fChatFrm.UserName = sUsername
  502.         fChatFrm.Show
  503.         fChatFrm.SetFocus
  504.         fChatFrm.AddChatMessage sChat
  505.     Case Msg_UserBlocked
  506.         'This user has blocked me
  507.         sUsername = GetStringFromBuffer(.ReceivedData, lOffset)
  508.         Set fChatFrm = GetMsgWindow(sUsername)
  509.         fChatFrm.UserName = sUsername
  510.         fChatFrm.Show
  511.         fChatFrm.SetFocus
  512.         fChatFrm.AddChatMessage "Your message to " & sUsername & " could not be delivered since they have blocked you.", , True
  513.     Case Msg_UserUnavailable
  514.         'This user is no longer available
  515.         sUsername = GetStringFromBuffer(.ReceivedData, lOffset)
  516.         sChat = GetStringFromBuffer(.ReceivedData, lOffset)
  517.         Set fChatFrm = GetMsgWindow(sUsername)
  518.         fChatFrm.UserName = sUsername
  519.         fChatFrm.Show
  520.         fChatFrm.SetFocus
  521.         fChatFrm.AddChatMessage "Your message: " & vbCrLf & sChat & vbCrLf & "to " & sUsername & " could not be delivered since they are no longer available.", , True
  522.     End Select
  523.     End With
  524. End Sub
  525. Private Sub DirectPlay8Event_SendComplete(dpnotify As DxVBLibA.DPNMSG_SEND_COMPLETE, fRejectMsg As Boolean)
  526.     'VB requires that we must implement *every* member of this interface
  527. End Sub
  528. Private Sub DirectPlay8Event_TerminateSession(dpnotify As DxVBLibA.DPNMSG_TERMINATE_SESSION, fRejectMsg As Boolean)
  529.     'We're no longer connected for some reason.
  530.     mfServerExit = True
  531. End Sub
  532.