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

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Begin VB.Form frmNetwork 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "vbConferencer"
  6.    ClientHeight    =   4365
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   3930
  10.    Icon            =   "frmNetwork.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   4365
  15.    ScaleWidth      =   3930
  16.    StartUpPosition =   3  'Windows Default
  17.    Begin MSComDlg.CommonDialog cdlSend 
  18.       Left            =   6360
  19.       Top             =   3180
  20.       _ExtentX        =   847
  21.       _ExtentY        =   847
  22.       _Version        =   393216
  23.       DialogTitle     =   "Send File"
  24.       Filter          =   "Any File |*.*"
  25.       Flags           =   4
  26.       InitDir         =   "C:\"
  27.    End
  28.    Begin VB.Timer tmrJoin 
  29.       Enabled         =   0   'False
  30.       Interval        =   50
  31.       Left            =   6420
  32.       Top             =   540
  33.    End
  34.    Begin VB.Timer tmrUpdate 
  35.       Enabled         =   0   'False
  36.       Interval        =   7500
  37.       Left            =   6420
  38.       Top             =   60
  39.    End
  40.    Begin VB.TextBox txtCall 
  41.       Height          =   285
  42.       Left            =   60
  43.       TabIndex        =   0
  44.       Top             =   300
  45.       Width           =   2535
  46.    End
  47.    Begin VB.ListBox lstUsers 
  48.       Height          =   2595
  49.       Left            =   60
  50.       TabIndex        =   3
  51.       Top             =   1020
  52.       Width           =   3795
  53.    End
  54.    Begin VB.CommandButton cmdHangup 
  55.       Height          =   495
  56.       Left            =   3240
  57.       MaskColor       =   &H00FF0000&
  58.       Picture         =   "frmNetwork.frx":030A
  59.       Style           =   1  'Graphical
  60.       TabIndex        =   2
  61.       ToolTipText     =   "Hang up"
  62.       Top             =   120
  63.       UseMaskColor    =   -1  'True
  64.       Width           =   495
  65.    End
  66.    Begin VB.CommandButton cmdCall 
  67.       Default         =   -1  'True
  68.       Height          =   495
  69.       Left            =   2700
  70.       MaskColor       =   &H000000FF&
  71.       Picture         =   "frmNetwork.frx":0A0C
  72.       Style           =   1  'Graphical
  73.       TabIndex        =   1
  74.       ToolTipText     =   "Call a friend"
  75.       Top             =   120
  76.       UseMaskColor    =   -1  'True
  77.       Width           =   495
  78.    End
  79.    Begin VB.CommandButton cmdWhiteBoard 
  80.       Height          =   495
  81.       Left            =   2325
  82.       MaskColor       =   &H000000FF&
  83.       Picture         =   "frmNetwork.frx":110E
  84.       Style           =   1  'Graphical
  85.       TabIndex        =   6
  86.       ToolTipText     =   "Use the whiteboard"
  87.       Top             =   3720
  88.       UseMaskColor    =   -1  'True
  89.       Width           =   495
  90.    End
  91.    Begin VB.CommandButton cmdChat 
  92.       Height          =   495
  93.       Left            =   1125
  94.       MaskColor       =   &H000000FF&
  95.       Picture         =   "frmNetwork.frx":1A18
  96.       Style           =   1  'Graphical
  97.       TabIndex        =   4
  98.       ToolTipText     =   "Chat with someone"
  99.       Top             =   3720
  100.       UseMaskColor    =   -1  'True
  101.       Width           =   495
  102.    End
  103.    Begin VB.CommandButton cmdSendFile 
  104.       Height          =   495
  105.       Left            =   1725
  106.       MaskColor       =   &H000000FF&
  107.       Picture         =   "frmNetwork.frx":2322
  108.       Style           =   1  'Graphical
  109.       TabIndex        =   5
  110.       ToolTipText     =   "Transfer files to someone"
  111.       Top             =   3720
  112.       UseMaskColor    =   -1  'True
  113.       Width           =   495
  114.    End
  115.    Begin VB.Label Label1 
  116.       BackStyle       =   0  'Transparent
  117.       Caption         =   "Enter a name or IP to call"
  118.       Height          =   195
  119.       Index           =   1
  120.       Left            =   60
  121.       TabIndex        =   8
  122.       Top             =   60
  123.       Width           =   2475
  124.    End
  125.    Begin VB.Label Label1 
  126.       BackStyle       =   0  'Transparent
  127.       Caption         =   "Users currently in this session"
  128.       Height          =   315
  129.       Index           =   0
  130.       Left            =   60
  131.       TabIndex        =   7
  132.       Top             =   780
  133.       Width           =   3735
  134.    End
  135.    Begin VB.Menu mnuPopup 
  136.       Caption         =   "PopUp"
  137.       Visible         =   0   'False
  138.       Begin VB.Menu mnuExit 
  139.          Caption         =   "E&xit"
  140.       End
  141.    End
  142. Attribute VB_Name = "frmNetwork"
  143. Attribute VB_GlobalNameSpace = False
  144. Attribute VB_Creatable = False
  145. Attribute VB_PredeclaredId = True
  146. Attribute VB_Exposed = False
  147. Option Explicit
  148. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  149. '  Copyright (C) 2000 Microsoft Corporation.  All Rights Reserved.
  150. '  File:       frmNetwork.frm
  151. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  152. Implements DirectPlay8Event
  153. Private Const mlFileChunkSize As Long = 512
  154. Private msFile As String
  155. Private mlFileSize As Long
  156. Private mlSendToID As Long
  157. Public msReceiveFile As String
  158. Public mlReceiveFileSize As Long
  159. Public mlReceiveSendToID As Long
  160. Private moCallBack As DirectPlay8Event
  161. Private mfExit As Boolean
  162. Private Sub cmdCall_Click()
  163.     If txtCall.Text = vbNullString Then
  164.         MsgBox "You must type the name or address of the person you wish to call before I can make the call.", vbOKOnly Or vbInformation, "No callee"
  165.         Exit Sub
  166.     End If
  167.     Connect Me, txtCall.Text
  168. End Sub
  169. Private Sub cmdChat_Click()
  170.     If lstUsers.ListCount < 2 Then
  171.         MsgBox "You must have at least two people in the session before you can chat.", vbOKOnly Or vbInformation, "Not enough people"
  172.         Exit Sub
  173.     End If
  174.     If ChatWindow Is Nothing Then Set ChatWindow = New frmChat
  175.     ChatWindow.Show vbModeless
  176.     'Notify everyone
  177.     SendOpenChatWindowMessage
  178.     Set moCallBack = ChatWindow
  179. End Sub
  180. Private Sub cmdHangup_Click()
  181.     'Cleanup and quit
  182.     mfExit = True
  183.     Unload Me
  184. End Sub
  185. Private Sub cmdSendFile_Click()
  186.     Dim lMsg As Long, lOffset As Long
  187.     Dim oBuf() As Byte
  188.     If msFile <> vbNullString Then
  189.         MsgBox "A previous file transfer is still ongoing, please wait for it to finish.", vbOKOnly Or vbInformation, "Wait"
  190.         Exit Sub
  191.     End If
  192.     If lstUsers.ListIndex < 0 Then
  193.         MsgBox "You must select someone to send a file to before sending one.", vbOKOnly Or vbInformation, "No selection"
  194.         Exit Sub
  195.     End If
  196.     If lstUsers.ListIndex < 1 Then
  197.         MsgBox "You must select someone other than yourself to send a file to before sending one.", vbOKOnly Or vbInformation, "No selection"
  198.         Exit Sub
  199.     End If
  200.     'Ok, we can send a file.. Let them pick one
  201.     cdlSend.FileName = vbNullString
  202.     On Error Resume Next
  203.     cdlSend.ShowOpen
  204.     If Err Then Exit Sub 'They clicked cancel
  205.     'Otherwise start the file send
  206.     'We need to send a 'Request' message first
  207.     lOffset = NewBuffer(oBuf)
  208.     lMsg = MsgSendFileRequest
  209.     AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  210.     AddStringToBuffer oBuf, StripFileName(cdlSend.FileName), lOffset
  211.     dpp.SendTo lstUsers.ItemData(lstUsers.ListIndex), oBuf, 0, DPNSEND_NOLOOPBACK
  212.     msFile = cdlSend.FileName
  213.     mlSendToID = lstUsers.ItemData(lstUsers.ListIndex)
  214. End Sub
  215. Private Sub cmdWhiteBoard_Click()
  216.     If lstUsers.ListCount < 2 Then
  217.         MsgBox "You must have at least two people in the session before you can use the whiteboard.", vbOKOnly Or vbInformation, "Not enough people"
  218.         Exit Sub
  219.     End If
  220.     If WhiteBoardWindow Is Nothing Then Set WhiteBoardWindow = New frmWhiteBoard
  221.     WhiteBoardWindow.Show vbModeless
  222.     'Notify everyone
  223.     SendOpenWhiteBoardWindowMessage
  224.     Set moCallBack = WhiteBoardWindow
  225. End Sub
  226. Private Sub Form_Load()
  227.     'First start our server.  We need to be running a server in case
  228.     'someone tries to connect to us.
  229.     StartHosting Me
  230.     'Add ourselves to the listbox
  231.     lstUsers.AddItem gsUserName
  232.     lstUsers.ItemData(0) = glMyPlayerID
  233.     'Now put up our system tray icon
  234.     With sysIcon
  235.         .cbSize = LenB(sysIcon)
  236.         .hwnd = Me.hwnd
  237.         .uFlags = NIF_DOALL
  238.         .uCallbackMessage = WM_MOUSEMOVE
  239.         .hIcon = Me.Icon
  240.         .sTip = "vbConferencer" & vbNullChar
  241.     End With
  242.     Shell_NotifyIcon NIM_ADD, sysIcon
  243. End Sub
  244. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  245.     Dim ShellMsg As Long
  246.     ShellMsg = X / Screen.TwipsPerPixelX
  247.     Select Case ShellMsg
  248.     Case WM_LBUTTONDBLCLK
  249.         ShowMyForm
  250.     Case WM_RBUTTONUP
  251.         'Show the menu
  252.         'If gfStarted Then mnuStart.Enabled = False
  253.         PopupMenu mnuPopup, , , , mnuExit
  254.     End Select
  255. End Sub
  256. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  257.     If Not mfExit Then
  258.         Cancel = 1
  259.         Me.Hide
  260.     End If
  261. End Sub
  262. Private Sub Form_Unload(Cancel As Integer)
  263.     Me.Hide
  264.     Shell_NotifyIcon NIM_DELETE, sysIcon
  265.     Cleanup
  266.     End
  267. End Sub
  268. Private Sub mnuExit_Click()
  269.     mfExit = True
  270.     Unload Me
  271. End Sub
  272. Private Sub ShowMyForm()
  273.     Me.Visible = True
  274. End Sub
  275. Private Sub tmrJoin_Timer()
  276.     tmrJoin.Enabled = False
  277.     MsgBox "The person you are trying to reach did not accept your call.", vbOKOnly Or vbInformation, "Didn't accept"
  278.     StartHosting Me
  279. End Sub
  280. Public Sub UpdatePlayerList()
  281.     Dim lCount As Long, dpPeer As DPN_PLAYER_INFO
  282.     Dim lInner As Long, fFound As Boolean
  283.     Dim lTotal As Long
  284.     lTotal = dpp.GetCountPlayersAndGroups(DPNENUM_PLAYERS)
  285.     If lTotal > 1 Then cmdHangup.Enabled = True
  286.     For lCount = 1 To lTotal
  287.         dpPeer = dpp.GetPeerInfo(dpp.GetPlayerOrGroup(lCount))
  288.         If (dpPeer.lPlayerFlags And DPNPLAYER_LOCAL) = DPNPLAYER_LOCAL Then
  289.             'Don't add me
  290.         Else
  291.             fFound = False
  292.             'Make sure they're not already added
  293.             For lInner = 0 To lstUsers.ListCount - 1
  294.                 If lstUsers.ItemData(lInner) = dpp.GetPlayerOrGroup(lCount) Then fFound = True
  295.             Next
  296.             If Not fFound Then
  297.                 'Go ahead and add them
  298.                 lstUsers.AddItem dpPeer.Name
  299.                 lstUsers.ItemData(lstUsers.ListCount - 1) = dpp.GetPlayerOrGroup(lCount)
  300.             End If
  301.         End If
  302.     Next
  303. End Sub
  304. Private Sub SendOpenWhiteBoardWindowMessage()
  305.     Dim lMsg As Long, lOffset As Long
  306.     Dim oBuf() As Byte
  307.     'Now let's send a message asking the host to accept our call
  308.     lOffset = NewBuffer(oBuf)
  309.     lMsg = MsgShowWhiteBoard
  310.     AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  311.     dpp.SendTo DPNID_ALL_PLAYERS_GROUP, oBuf, 0, DPNSEND_NOLOOPBACK
  312. End Sub
  313. Private Sub SendOpenChatWindowMessage()
  314.     Dim lMsg As Long, lOffset As Long
  315.     Dim oBuf() As Byte
  316.     'Now let's send a message asking the host to accept our call
  317.     lOffset = NewBuffer(oBuf)
  318.     lMsg = MsgShowChat
  319.     AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  320.     dpp.SendTo DPNID_ALL_PLAYERS_GROUP, oBuf, 0, DPNSEND_NOLOOPBACK
  321. End Sub
  322. Private Sub RemovePlayer(ByVal lPlayerID As Long)
  323.     Dim lCount As Long
  324.     'Remove anyone who has this player id
  325.     For lCount = 0 To lstUsers.ListCount - 1
  326.         If lstUsers.ItemData(lCount) = lPlayerID Then lstUsers.RemoveItem lCount
  327.     Next
  328. End Sub
  329. Private Function StripFileName(ByVal sFile As String) As String
  330.     'Get rid of the path to the file (Strip everything after the last \)
  331.     If InStr(sFile, "\") Then
  332.         StripFileName = Right$(sFile, Len(sFile) - InStrRev(sFile, "\"))
  333.     Else
  334.         StripFileName = sFile
  335.     End If
  336. End Function
  337. Private Sub SendNextFilePart()
  338.     Dim lNewMsg As Long, lNewOffSet As Long
  339.     Dim oBuf() As Byte
  340.     Dim lChunkSize As Long
  341.     Static lFilePart As Long
  342.     Static lSendCurPos As Long
  343.     Static filSend As Long
  344.     Dim oFile() As Byte
  345.     lFilePart = lFilePart + 1
  346.     'Send this chunk
  347.     lNewOffSet = NewBuffer(oBuf)
  348.     lNewMsg = MsgSendFilePart
  349.     AddDataToBuffer oBuf, lNewMsg, LenB(lNewMsg), lNewOffSet
  350.     'Is this chunk bigger than the amount we will send?
  351.     If lSendCurPos + mlFileChunkSize > mlFileSize Then
  352.         'First send the chunksize
  353.         lChunkSize = mlFileSize - lSendCurPos
  354.     Else
  355.         lChunkSize = mlFileChunkSize
  356.     End If
  357.     AddDataToBuffer oBuf, lChunkSize, LenB(lChunkSize), lNewOffSet
  358.     ReDim oFile(1 To lChunkSize)
  359.     'Now read in a chunk that size
  360.     If filSend = 0 Then
  361.         filSend = FreeFile
  362.         Open msFile For Binary Access Read As #filSend
  363.     End If
  364.     Get #filSend, , oFile
  365.     AddDataToBuffer oBuf, oFile(1), lChunkSize, lNewOffSet
  366.     dpp.SendTo mlSendToID, oBuf, 0, DPNSEND_NOLOOPBACK
  367.     lSendCurPos = lSendCurPos + lChunkSize
  368.     If lSendCurPos >= mlFileSize Then
  369.         Close #filSend
  370.         filSend = 0
  371.         lSendCurPos = 0
  372.         lFilePart = 0
  373.         msFile = vbNullString
  374.         mlFileSize = 0
  375.         mlSendToID = 0
  376.     End If
  377. End Sub
  378. 'We will handle all of the msgs here, and report them all back to the callback sub
  379. 'in case the caller cares what's going on
  380. Private Sub DirectPlay8Event_AddRemovePlayerGroup(ByVal lMsgID As Long, ByVal lPlayerID As Long, ByVal lGroupID As Long, fRejectMsg As Boolean)
  381.     'VB requires that we must implement *every* member of this interface
  382.     If (Not moCallBack Is Nothing) Then moCallBack.AddRemovePlayerGroup lMsgID, lPlayerID, lGroupID, fRejectMsg
  383. End Sub
  384. Private Sub DirectPlay8Event_AppDesc(fRejectMsg As Boolean)
  385.     'VB requires that we must implement *every* member of this interface
  386.     If (Not moCallBack Is Nothing) Then moCallBack.AppDesc fRejectMsg
  387. End Sub
  388. Private Sub DirectPlay8Event_AsyncOpComplete(dpnotify As DxVBLibA.DPNMSG_ASYNC_OP_COMPLETE, fRejectMsg As Boolean)
  389.     'VB requires that we must implement *every* member of this interface
  390.     If (Not moCallBack Is Nothing) Then moCallBack.AsyncOpComplete dpnotify, fRejectMsg
  391. End Sub
  392. Private Sub DirectPlay8Event_ConnectComplete(dpnotify As DxVBLibA.DPNMSG_CONNECT_COMPLETE, fRejectMsg As Boolean)
  393.     Dim lMsg As Long, lOffset As Long
  394.     Dim oBuf() As Byte
  395.     If dpnotify.hResultCode = 0 Then 'Success!
  396.         cmdHangup.Enabled = True
  397.         'Now let's send a message asking the host to accept our call
  398.         lOffset = NewBuffer(oBuf)
  399.         lMsg = MsgAskToJoin
  400.         AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  401.         dpp.SendTo DPNID_ALL_PLAYERS_GROUP, oBuf, 0, DPNSEND_NOLOOPBACK
  402.     Else
  403.         tmrUpdate.Enabled = True
  404.     End If
  405.     'VB requires that we must implement *every* member of this interface
  406.     If (Not moCallBack Is Nothing) Then moCallBack.ConnectComplete dpnotify, fRejectMsg
  407. End Sub
  408. Private Sub DirectPlay8Event_CreateGroup(ByVal lGroupID As Long, ByVal lOwnerID As Long, fRejectMsg As Boolean)
  409.     'VB requires that we must implement *every* member of this interface
  410.     If (Not moCallBack Is Nothing) Then moCallBack.CreateGroup lGroupID, lOwnerID, fRejectMsg
  411. End Sub
  412. Private Sub DirectPlay8Event_CreatePlayer(ByVal lPlayerID As Long, fRejectMsg As Boolean)
  413.     Dim dpPeer As DPN_PLAYER_INFO
  414.     On Error Resume Next
  415.     dpPeer = dpp.GetPeerInfo(lPlayerID)
  416.     If (dpPeer.lPlayerFlags And DPNPLAYER_LOCAL) = DPNPLAYER_LOCAL Then
  417.         glMyPlayerID = lPlayerID
  418.         lstUsers.ItemData(0) = glMyPlayerID
  419.     End If
  420.     'VB requires that we must implement *every* member of this interface
  421.     If (Not moCallBack Is Nothing) Then moCallBack.CreatePlayer lPlayerID, fRejectMsg
  422. End Sub
  423. Private Sub DirectPlay8Event_DestroyGroup(ByVal lGroupID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  424.     'VB requires that we must implement *every* member of this interface
  425.     If (Not moCallBack Is Nothing) Then moCallBack.DestroyGroup lGroupID, lReason, fRejectMsg
  426. End Sub
  427. Private Sub DirectPlay8Event_DestroyPlayer(ByVal lPlayerID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  428.     Dim dpPeer As DPN_PLAYER_INFO
  429.     On Error Resume Next
  430.     If lPlayerID <> glMyPlayerID Then 'ignore removing myself
  431.         RemovePlayer lPlayerID
  432.     End If
  433.     'VB requires that we must implement *every* member of this interface
  434.     If (Not moCallBack Is Nothing) Then moCallBack.DestroyPlayer lPlayerID, lReason, fRejectMsg
  435. End Sub
  436. Private Sub DirectPlay8Event_EnumHostsQuery(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_QUERY, fRejectMsg As Boolean)
  437.     'VB requires that we must implement *every* member of this interface
  438.     If (Not moCallBack Is Nothing) Then moCallBack.EnumHostsQuery dpnotify, fRejectMsg
  439. End Sub
  440. Private Sub DirectPlay8Event_EnumHostsResponse(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_RESPONSE, fRejectMsg As Boolean)
  441.     'VB requires that we must implement *every* member of this interface
  442.     If (Not moCallBack Is Nothing) Then moCallBack.EnumHostsResponse dpnotify, fRejectMsg
  443. End Sub
  444. Private Sub DirectPlay8Event_HostMigrate(ByVal lNewHostID As Long, fRejectMsg As Boolean)
  445.     'VB requires that we must implement *every* member of this interface
  446.     If (Not moCallBack Is Nothing) Then moCallBack.HostMigrate lNewHostID, fRejectMsg
  447. End Sub
  448. Private Sub DirectPlay8Event_IndicateConnect(dpnotify As DxVBLibA.DPNMSG_INDICATE_CONNECT, fRejectMsg As Boolean)
  449.     'VB requires that we must implement *every* member of this interface
  450.     If (Not moCallBack Is Nothing) Then moCallBack.IndicateConnect dpnotify, fRejectMsg
  451. End Sub
  452. Private Sub DirectPlay8Event_IndicatedConnectAborted(fRejectMsg As Boolean)
  453.     'VB requires that we must implement *every* member of this interface
  454.     If (Not moCallBack Is Nothing) Then moCallBack.IndicatedConnectAborted fRejectMsg
  455. End Sub
  456. Private Sub DirectPlay8Event_InfoNotify(ByVal lMsgID As Long, ByVal lNotifyID As Long, fRejectMsg As Boolean)
  457.     'VB requires that we must implement *every* member of this interface
  458.     If (Not moCallBack Is Nothing) Then moCallBack.InfoNotify lMsgID, lNotifyID, fRejectMsg
  459. End Sub
  460. Private Sub DirectPlay8Event_Receive(dpnotify As DxVBLibA.DPNMSG_RECEIVE, fRejectMsg As Boolean)
  461.     Dim lNewMsg As Long, lNewOffSet As Long
  462.     Dim oBuf() As Byte
  463.     Dim lMsg As Long, lOffset As Long
  464.     Dim frmJoin As frmJoinRequest
  465.     Dim frmTrans As frmTransferRequest
  466.     Dim dpPeer As DPN_PLAYER_INFO
  467.     Dim sFile As String
  468.     Static lFilePart As Long
  469.     Static lSendCurPos As Long
  470.     Static filSend As Long
  471.     Dim oFile() As Byte
  472.     Static fil As Long, lCurPos As Long
  473.     Dim lChunkSize As Long, oData() As Byte
  474.     With dpnotify
  475.     GetDataFromBuffer .ReceivedData, lMsg, LenB(lMsg), lOffset
  476.     Select Case lMsg
  477.     Case MsgChat, MsgWhisper 'Make sure chat messages get to the chat window
  478.         If ObjPtr(moCallBack) <> ObjPtr(ChatWindow) Then
  479.             If ChatWindow Is Nothing Then
  480.                 Set ChatWindow = New frmChat
  481.             End If
  482.             ChatWindow.Show
  483.             Set moCallBack = ChatWindow
  484.         End If
  485.     Case MsgSendDrawPixel, MsgClearWhiteBoard
  486.         If ObjPtr(moCallBack) <> ObjPtr(WhiteBoardWindow) Then
  487.             If WhiteBoardWindow Is Nothing Then
  488.                 Set WhiteBoardWindow = New frmWhiteBoard
  489.             End If
  490.             WhiteBoardWindow.Show
  491.             Set moCallBack = WhiteBoardWindow
  492.         End If
  493.     Case MsgAskToJoin
  494.         If gfHost Then
  495.             'We are the host, pop up the 'Ask to join dialog
  496.             dpPeer = dpp.GetPeerInfo(dpnotify.idSender)
  497.             Set frmJoin = New frmJoinRequest
  498.             frmJoin.SetupRequest Me, dpnotify.idSender, dpPeer.Name
  499.             frmJoin.Show vbModeless
  500.         End If
  501.     Case MsgAcceptJoin
  502.         'We have been accepted
  503.         'Enumerate all the players and add anyone we don't already have listed
  504.         UpdatePlayerList
  505.         ConnectVoice
  506.     Case MsgRejectJoin
  507.         'We have been rejected
  508.         tmrJoin.Enabled = True
  509.         'We need to use a timer here, without it, we would be attempting to cleanup
  510.         'our dplay objects to restart our host before this message was done being processed.
  511.     Case MsgShowChat
  512.         'Someone wants to chat.  Open the chat window
  513.         If ChatWindow Is Nothing Then Set ChatWindow = New frmChat
  514.         ChatWindow.Show vbModeless
  515.         Set moCallBack = ChatWindow
  516.     Case MsgShowWhiteBoard
  517.         'Someone wants to draw.  Open the whiteboard window
  518.         If WhiteBoardWindow Is Nothing Then Set WhiteBoardWindow = New frmWhiteBoard
  519.         WhiteBoardWindow.Show vbModeless
  520.         Set moCallBack = WhiteBoardWindow
  521.     Case MsgSendFileRequest
  522.         'Someone wants to send us a file.  Should we accept?
  523.         sFile = GetStringFromBuffer(.ReceivedData, lOffset)
  524.         msReceiveFile = sFile
  525.         mlReceiveSendToID = dpnotify.idSender
  526.         dpPeer = dpp.GetPeerInfo(dpnotify.idSender)
  527.         Set frmTrans = New frmTransferRequest
  528.         frmTrans.SetupRequest Me, dpnotify.idSender, dpPeer.Name, sFile
  529.         frmTrans.Show vbModeless
  530.     Case MsgSendFileDeny
  531.         'We don't care about this file
  532.         msFile = vbNullString
  533.         mlFileSize = 0
  534.         mlSendToID = 0
  535.     Case MsgSendFileAccept
  536.         'Ok, they do want us to send the file to them.. We will send it in chunks
  537.         'First we will send the file info
  538.         lNewOffSet = NewBuffer(oBuf)
  539.         lMsg = MsgSendFileInfo
  540.         AddDataToBuffer oBuf, lMsg, LenB(lMsg), lNewOffSet
  541.         mlFileSize = FileLen(msFile)
  542.         AddDataToBuffer oBuf, mlFileSize, LenB(mlFileSize), lNewOffSet
  543.         dpp.SendTo mlSendToID, oBuf, 0, DPNSEND_NOLOOPBACK Or DPNSEND_GUARANTEED
  544.         SendNextFilePart
  545.     Case MsgSendFileInfo
  546.         'They just send us the file size, save it
  547.         GetDataFromBuffer .ReceivedData, mlReceiveFileSize, LenB(mlReceiveFileSize), lOffset
  548.         frmProgress.Show
  549.         frmProgress.SetFile msReceiveFile
  550.         frmProgress.SetMax mlReceiveFileSize
  551.         frmProgress.SetValue 0
  552.     Case MsgSendFilePart
  553.         GetDataFromBuffer .ReceivedData, lChunkSize, LenB(lChunkSize), lOffset
  554.         ReDim oData(1 To lChunkSize)
  555.         'We just received a file part..  Append this to our current file
  556.         If fil = 0 Then
  557.             fil = FreeFile
  558.             If Dir$(App.Path & "\" & msReceiveFile) <> vbNullString Then Kill App.Path & "\" & msReceiveFile
  559.             Open App.Path & "\" & msReceiveFile For Binary Access Write As #fil
  560.         End If
  561.         GetDataFromBuffer .ReceivedData, oData(1), lChunkSize, lOffset
  562.         Put #fil, , oData
  563.         'Is this the end of the file?
  564.         lCurPos = lCurPos + lChunkSize
  565.         frmProgress.SetValue lCurPos
  566.         If lCurPos >= mlReceiveFileSize Then
  567.             'We're done with the file
  568.             Close #fil
  569.             MsgBox "Successfully received " & msReceiveFile & ".", vbOKOnly Or vbInformation, "Complete"
  570.             Unload frmProgress
  571.             mlReceiveFileSize = 0
  572.             msReceiveFile = vbNullString
  573.             fil = 0
  574.             lCurPos = 0
  575.         Else
  576.             'Acknowledge that we received this part
  577.             lNewMsg = MsgAckFilePart
  578.             lNewOffSet = NewBuffer(oBuf)
  579.             AddDataToBuffer oBuf, lNewMsg, LenB(lNewMsg), lNewOffSet
  580.             dpp.SendTo dpnotify.idSender, oBuf, 0, DPNSEND_NOLOOPBACK Or DPNSEND_GUARANTEED
  581.         End If
  582.     Case MsgAckFilePart
  583.         SendNextFilePart
  584.     End Select
  585.     End With
  586.     If (Not moCallBack Is Nothing) Then moCallBack.Receive dpnotify, fRejectMsg
  587. End Sub
  588. Private Sub DirectPlay8Event_SendComplete(dpnotify As DxVBLibA.DPNMSG_SEND_COMPLETE, fRejectMsg As Boolean)
  589.     'VB requires that we must implement *every* member of this interface
  590.     If (Not moCallBack Is Nothing) Then moCallBack.SendComplete dpnotify, fRejectMsg
  591. End Sub
  592. Private Sub DirectPlay8Event_TerminateSession(dpnotify As DxVBLibA.DPNMSG_TERMINATE_SESSION, fRejectMsg As Boolean)
  593.     'VB requires that we must implement *every* member of this interface
  594.     If (Not moCallBack Is Nothing) Then moCallBack.TerminateSession dpnotify, fRejectMsg
  595. End Sub
  596. Private Sub tmrUpdate_Timer()
  597.     tmrUpdate.Enabled = False
  598.     MsgBox "The person you are trying to reach is not available.", vbOKOnly Or vbInformation, "Unavailable"
  599.     StartHosting Me
  600. End Sub
  601.