home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8vbsdk.exe / samples / multimedia / vbsamples / directplay / voicegroup / dplay.bas next >
Encoding:
BASIC Source File  |  2000-10-11  |  2.8 KB  |  97 lines

  1. Attribute VB_Name = "DplayModule"
  2. Option Explicit
  3.  
  4. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  5. '
  6. '  Copyright (C) 2000 Microsoft Corporation.  All Rights Reserved.
  7. '
  8. '  File:       dplay.bas
  9. '
  10. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  11. Public Enum DPLAY_MSGS
  12.     MSG_CHANGEGROUP
  13.     MSG_CHANGETALK
  14.     MSG_SERVERCHANGEGROUP
  15. End Enum
  16.  
  17. 'Constants
  18. Public Const AppGuid = "{F5230441-9B71-88DA-998C-00207547A14D}"
  19.  
  20. 'DirectX Variables
  21. Public dvServer As DirectPlayVoiceServer8
  22. Public dvClient As DirectPlayVoiceClient8
  23. Public dx As DirectX8
  24. Public dpp As DirectPlay8Peer
  25. Public oSession As DVSESSIONDESC
  26. Public oSound As DVSOUNDDEVICECONFIG
  27. Public oClient As DVCLIENTCONFIG
  28.  
  29. Public glGroupID(1 To 5) As Long
  30.  
  31. 'Misc Vars
  32. Public glMyPlayerID As Long
  33. Public fGotSettings As Boolean
  34.  
  35. Public DPlayEventsForm As DPlayConnect
  36.  
  37. Public Sub InitDPlay()
  38.     Set dx = New DirectX8
  39.     Set dpp = dx.DirectPlayPeerCreate
  40.     Set dvServer = dx.DirectPlayVoiceServerCreate
  41.     Set dvClient = dx.DirectPlayVoiceClientCreate
  42. End Sub
  43.  
  44. Public Sub Cleanup()
  45.     
  46.     On Error Resume Next
  47.     'Turn off our error handling
  48.     If Not (DPlayEventsForm Is Nothing) Then
  49.         If Not (dpp Is Nothing) Then dpp.UnRegisterMessageHandler
  50.         If Not (dvClient Is Nothing) Then dvClient.UnRegisterMessageHandler
  51.         If Not (dvServer Is Nothing) Then dvServer.UnRegisterMessageHandler
  52.         dvClient.Disconnect 0
  53.         DPlayEventsForm.DoSleep 50
  54.         If DPlayEventsForm.IsHost Then dvServer.StopSession 0
  55.         
  56.         If Not dpp Is Nothing Then dpp.Close
  57.         DPlayEventsForm.GoUnload
  58.         'Destroy the objects
  59.         Set dvClient = Nothing
  60.         Set dvServer = Nothing
  61.         Set dpp = Nothing
  62.         Set dx = Nothing
  63.     End If
  64. End Sub
  65.     
  66. Private Sub Main()
  67.     'Here is where we will start
  68.     InitDPlay
  69.     
  70.     Set DPlayEventsForm = New DPlayConnect
  71.     If Not DPlayEventsForm.StartConnectWizard(dx, dpp, AppGuid, 20) Then
  72.         Cleanup
  73.     Else 'We did choose to play a game
  74.         If Not (DPlayEventsForm.IsHost) Then frmVoiceSettings.ClientOnly
  75.         frmVoiceSettings.Show vbModal
  76.         If Not fGotSettings Then 'We quit for some unknown reason.
  77.             Cleanup
  78.             Exit Sub
  79.         End If
  80.         frmVoice.Show vbModeless
  81.         frmVoice.Caption = frmVoice.Caption & " (HOST)"
  82.     End If
  83.     
  84. End Sub
  85.  
  86. Public Sub RemovePlayerFromAllGroups(lPlayerID As Long)
  87.     On Error Resume Next 'We don't care about any errors..
  88.     Dim lCount As Long
  89.     
  90.     For lCount = 1 To 5
  91.         dpp.RemovePlayerFromGroup glGroupID(lCount), lPlayerID, 0
  92.     Next
  93.     Err.Clear
  94.     'Ignore the errors about Player not in group
  95. End Sub
  96.  
  97.