home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8vbsdk.exe / samples / multimedia / vbsamples / directplay / conferencer / frmchat.frm (.txt) next >
Encoding:
Visual Basic Form  |  2000-10-02  |  9.3 KB  |  222 lines

  1. VERSION 5.00
  2. Begin VB.Form frmChat 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "vbDirectPlay Chat"
  5.    ClientHeight    =   5085
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   7710
  9.    Icon            =   "frmChat.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   5085
  14.    ScaleWidth      =   7710
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.CommandButton cmdWhisper 
  17.       Caption         =   "Whisper"
  18.       Height          =   255
  19.       Left            =   5820
  20.       TabIndex        =   3
  21.       Top             =   4740
  22.       Width           =   1695
  23.    End
  24.    Begin VB.Timer tmrUpdate 
  25.       Enabled         =   0   'False
  26.       Interval        =   50
  27.       Left            =   10200
  28.       Top             =   120
  29.    End
  30.    Begin VB.TextBox txtSend 
  31.       Height          =   285
  32.       Left            =   60
  33.       TabIndex        =   0
  34.       Top             =   4740
  35.       Width           =   5655
  36.    End
  37.    Begin VB.ListBox lstUsers 
  38.       Height          =   4545
  39.       Left            =   5760
  40.       TabIndex        =   2
  41.       Top             =   120
  42.       Width           =   1815
  43.    End
  44.    Begin VB.TextBox txtChat 
  45.       Height          =   4635
  46.       Left            =   60
  47.       MultiLine       =   -1  'True
  48.       ScrollBars      =   3  'Both
  49.       TabIndex        =   1
  50.       TabStop         =   0   'False
  51.       Top             =   60
  52.       Width           =   5595
  53.    End
  54. Attribute VB_Name = "frmChat"
  55. Attribute VB_GlobalNameSpace = False
  56. Attribute VB_Creatable = False
  57. Attribute VB_PredeclaredId = True
  58. Attribute VB_Exposed = False
  59. Option Explicit
  60. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  61. '  Copyright (C) 2000 Microsoft Corporation.  All Rights Reserved.
  62. '  File:       frmChat.frm
  63. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  64. Implements DirectPlay8Event
  65. Private Sub cmdWhisper_Click()
  66.     Dim lMsg As Long, lOffset As Long
  67.     Dim sChatMsg As String
  68.     Dim oBuf() As Byte
  69.     If lstUsers.ListIndex < 0 Then
  70.         MsgBox "You must select a user in the list before you can whisper to that person.", vbOKOnly Or vbInformation, "Select someone"
  71.         Exit Sub
  72.     End If
  73.     If lstUsers.ItemData(lstUsers.ListIndex) = 0 Then
  74.         MsgBox "Why are you whispering to yourself?", vbOKOnly Or vbInformation, "Select someone else"
  75.         Exit Sub
  76.     End If
  77.     If txtSend.Text = vbNullString Then
  78.         MsgBox "What's the point of whispering if you have nothing to say..", vbOKOnly Or vbInformation, "Enter text"
  79.         Exit Sub
  80.     End If
  81.         
  82.     'Send this message to the person you are whispering to
  83.     lMsg = MsgWhisper
  84.     lOffset = NewBuffer(oBuf)
  85.     AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  86.     sChatMsg = txtSend.Text
  87.     AddStringToBuffer oBuf, sChatMsg, lOffset
  88.     txtSend.Text = vbNullString
  89.     dpp.SendTo lstUsers.ItemData(lstUsers.ListIndex), oBuf, 0, DPNSEND_NOLOOPBACK
  90.     UpdateChat "**<" & gsUserName & ">** " & sChatMsg
  91. End Sub
  92. Private Sub Form_Load()
  93.     'load all of the players into our list
  94.     LoadAllPlayers
  95. End Sub
  96. Private Sub UpdateChat(ByVal sString As String)
  97.     'Update the chat window first
  98.     txtChat.Text = txtChat.Text & sString & vbCrLf
  99.     'Now limit the text in the window to be 16k
  100.     If Len(txtChat.Text) > 16384 Then
  101.         txtChat.Text = Right$(txtChat.Text, 16384)
  102.     End If
  103.     'Autoscroll the text
  104.     txtChat.SelStart = Len(txtChat.Text)
  105. End Sub
  106. Private Sub txtSend_KeyPress(KeyAscii As Integer)
  107.     Dim lMsg As Long, lOffset As Long
  108.     Dim sChatMsg As String
  109.     Dim oBuf() As Byte
  110.     If KeyAscii = vbKeyReturn Then
  111.         'Send this message to everyone
  112.         lMsg = MsgChat
  113.         lOffset = NewBuffer(oBuf)
  114.         AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  115.         sChatMsg = txtSend.Text
  116.         AddStringToBuffer oBuf, sChatMsg, lOffset
  117.         txtSend.Text = vbNullString
  118.         KeyAscii = 0
  119.         dpp.SendTo DPNID_ALL_PLAYERS_GROUP, oBuf, 0, DPNSEND_NOLOOPBACK
  120.         UpdateChat "<" & gsUserName & ">" & sChatMsg
  121.     End If
  122. End Sub
  123. Private Function GetName(ByVal lID As Long) As String
  124.     Dim lCount As Long
  125.     GetName = vbNullString
  126.     For lCount = 0 To lstUsers.ListCount - 1
  127.         If lstUsers.ItemData(lCount) = lID Then 'This is the player
  128.             GetName = lstUsers.List(lCount)
  129.             Exit For
  130.         End If
  131.     Next
  132. End Function
  133. Public Sub LoadAllPlayers()
  134.     Dim lCount As Long
  135.     Dim dpPlayer As DPN_PLAYER_INFO
  136.     For lCount = 1 To dpp.GetCountPlayersAndGroups(DPNENUM_PLAYERS)
  137.         dpPlayer = dpp.GetPeerInfo(dpp.GetPlayerOrGroup(lCount))
  138.         lstUsers.AddItem dpPlayer.Name
  139.         If ((dpPlayer.lPlayerFlags And DPNPLAYER_LOCAL) <> DPNPLAYER_LOCAL) Then
  140.             'Do not add a ItemData key for myself
  141.             lstUsers.ItemData(lstUsers.ListCount - 1) = dpp.GetPlayerOrGroup(lCount)
  142.         End If
  143.     Next
  144. End Sub
  145. Private Sub DirectPlay8Event_AddRemovePlayerGroup(ByVal lMsgID As Long, ByVal lPlayerID As Long, ByVal lGroupID As Long, fRejectMsg As Boolean)
  146.     'VB requires that we must implement *every* member of this interface
  147. End Sub
  148. Private Sub DirectPlay8Event_AppDesc(fRejectMsg As Boolean)
  149.     'VB requires that we must implement *every* member of this interface
  150. End Sub
  151. Private Sub DirectPlay8Event_AsyncOpComplete(dpnotify As DxVBLibA.DPNMSG_ASYNC_OP_COMPLETE, fRejectMsg As Boolean)
  152.     'VB requires that we must implement *every* member of this interface
  153. End Sub
  154. Private Sub DirectPlay8Event_ConnectComplete(dpnotify As DxVBLibA.DPNMSG_CONNECT_COMPLETE, fRejectMsg As Boolean)
  155.     'VB requires that we must implement *every* member of this interface
  156. End Sub
  157. Private Sub DirectPlay8Event_CreateGroup(ByVal lGroupID As Long, ByVal lOwnerID As Long, fRejectMsg As Boolean)
  158.     'VB requires that we must implement *every* member of this interface
  159. End Sub
  160. Private Sub DirectPlay8Event_CreatePlayer(ByVal lPlayerID As Long, fRejectMsg As Boolean)
  161.     'VB requires that we must implement *every* member of this interface
  162. End Sub
  163. Private Sub DirectPlay8Event_DestroyGroup(ByVal lGroupID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  164.     'VB requires that we must implement *every* member of this interface
  165. End Sub
  166. Private Sub DirectPlay8Event_DestroyPlayer(ByVal lPlayerID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  167.     Dim lCount As Long
  168.     'We only care when someone leaves.  When they join we will receive a 'MSGJoin'
  169.     'Remove this player from our list
  170.     For lCount = 0 To lstUsers.ListCount - 1
  171.         If lstUsers.ItemData(lCount) = lPlayerID Then 'This is the player
  172.             UpdateChat "---- " & lstUsers.List(lCount) & " has left the chat."
  173.             lstUsers.RemoveItem lCount
  174.             Exit For
  175.         End If
  176.     Next
  177. End Sub
  178. Private Sub DirectPlay8Event_EnumHostsQuery(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_QUERY, fRejectMsg As Boolean)
  179.     'VB requires that we must implement *every* member of this interface
  180. End Sub
  181. Private Sub DirectPlay8Event_EnumHostsResponse(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_RESPONSE, fRejectMsg As Boolean)
  182.     'VB requires that we must implement *every* member of this interface
  183. End Sub
  184. Private Sub DirectPlay8Event_HostMigrate(ByVal lNewHostID As Long, fRejectMsg As Boolean)
  185.     'VB requires that we must implement *every* member of this interface
  186. End Sub
  187. Private Sub DirectPlay8Event_IndicateConnect(dpnotify As DxVBLibA.DPNMSG_INDICATE_CONNECT, fRejectMsg As Boolean)
  188.     'VB requires that we must implement *every* member of this interface
  189. End Sub
  190. Private Sub DirectPlay8Event_IndicatedConnectAborted(fRejectMsg As Boolean)
  191.     'VB requires that we must implement *every* member of this interface
  192. End Sub
  193. Private Sub DirectPlay8Event_InfoNotify(ByVal lMsgID As Long, ByVal lNotifyID As Long, fRejectMsg As Boolean)
  194.     'VB requires that we must implement *every* member of this interface
  195. End Sub
  196. Private Sub DirectPlay8Event_Receive(dpnotify As DxVBLibA.DPNMSG_RECEIVE, fRejectMsg As Boolean)
  197.     'process what msgs we receive.
  198.     'All we care about in this form is what msgs we receive.
  199.     Dim lMsg As Long, lOffset As Long
  200.     Dim dpPeer As DPN_PLAYER_INFO, sName As String
  201.     Dim sChat As String
  202.     With dpnotify
  203.     GetDataFromBuffer .ReceivedData, lMsg, LenB(lMsg), lOffset
  204.     Select Case lMsg
  205.     Case MsgChat
  206.         sName = GetName(.idSender)
  207.         sChat = GetStringFromBuffer(.ReceivedData, lOffset)
  208.         UpdateChat "<" & sName & "> " & sChat
  209.     Case MsgWhisper
  210.         sName = GetName(.idSender)
  211.         sChat = GetStringFromBuffer(.ReceivedData, lOffset)
  212.         UpdateChat "**<" & sName & ">** " & sChat
  213.     End Select
  214.     End With
  215. End Sub
  216. Private Sub DirectPlay8Event_SendComplete(dpnotify As DxVBLibA.DPNMSG_SEND_COMPLETE, fRejectMsg As Boolean)
  217.     'VB requires that we must implement *every* member of this interface
  218. End Sub
  219. Private Sub DirectPlay8Event_TerminateSession(dpnotify As DxVBLibA.DPNMSG_TERMINATE_SESSION, fRejectMsg As Boolean)
  220.     'VB requires that we must implement *every* member of this interface
  221. End Sub
  222.