这样的文章相当少,提供给你一个连接:
http://rookscape.com/vbgaming/tutX.php
你可以到 www.google.com 上以DirectPlay +VB做关键字查找。
http://rookscape.com/vbgaming/tutX.php
你可以到 www.google.com 上以DirectPlay +VB做关键字查找。
解决方案 »
- VB 文件操作
- VB中如何更改操作系统的时间格式和日期格式为指定格式
- 一个有意思的问题!!关于select的问题
- 如何在TreeView控件中加入条目?(急)
- 高手来帮我看下这段代码行不?
- 如何在IE上加装一个工具菜单,就像网易的easebar一样,最好给个例子
- 又一个查询请教!
- 请教高手,动态生成控件的问题:
- 大家一起努力学VB,
- 求助!Spy++抓不到的控件,不用api hook,还有什么办法能得到该控件的相关信息?
- 一断源码..有点问题..关于数组的...............我是老山..快......
- MaskedEdit Box小问题,如何在此控件获得焦点后,光标放在左侧,而不是光标点击处
=================================================================
'发消息部分
const MyGame_ChatMessage = 0
const MyGame_DataPacket = 1
const MyGame_SomeOtherType = 2
const MyGame_YetAnotherMessageType = 3
'This object holds everything that we need to send.
Dim Msg As DirectPlayMessage'Use DirectPlay to initialise our message object.
Set Msg = Dp.CreateMessage
Msg.WriteLong MyGame_ChatMessage 'The message will hold an identifier
Msg.WriteString "Hello. I am a chat string." 'Stick the string data here
'There are several different data types you can write into the message; and you can use more than one:
'WriteSingle = Any valid single data type (ie. Decimal number)
'WriteDouble = Any valid Double data type (Same as a single, but bigger)
'WriteShort = Any valid Integer data type
'WriteLong = Any valid Long data type (Same as integer, but bigger)
'WriteGUID = Writes a string to the message - Almost identical to the WriteString method
'WriteString = Write any string to the message, this can be used to send data packets
'WriteByte = Writes a byte to the message'Now that we've compiled our message into a single structure; we can send it to a single player,
' or lots of players.dp.SendEx PlayerID, DPID_ALLPLAYERS, DPSEND_GUARANTEED, Msg, 0, 0, 0 .=================================================================
'接收消息部分:
Dim FromThisPlayer as long, ToThisPlayer as long, NumMessagesWaiting as long, MsgType as Long
Dim Msg as DirectPlayMessageNumMessagesWaiting = Dp.GetMessageCount(PlayerID) 'check the messages for our Player ONLYDo While NumMessagesWaiting >0
Set Msg = Dp.Recieve(FromThisPlayer, ToThisPlayer, DPRECIEVE_ALL)
'The variables FromThisPlayer and ToThisPlayer have the ID numbers of their respective players.
'DPRECIEVE_ALL basically means that we look at all the messages. We can now unpack the dataMsgType = Msg.ReadLong()
'Now we process the message - we'll do this in another procedure...
ProcessMessage MsgType, FromThisPlayer'Now we decrement the number of messages waiting - to clear the message we just read.
NumMessagesWaiting = NumMessagesWaiting -1
Loop
Sub ProcessMessage(Type as Long, From as Long)
If From = DPID_SYSMSG then
'We have a message from the DirectPlay system. There are a lot of System Messages; the most important ones
'Being:
'DPSYS _CREATEPLAYERORGROUP - A new player or group have joined
'DPSYS _DESTROYPLAYERORGROUP - An existing player has left
'DPSYS_HOST - The current host has left the game; the application that recieves this is now the new host.
'DPSYS _SESSIONLOST - The connection with the session has been lost.
Else
'We Have a message of custom-Type. The best method is to use a Select Case:
Select Case Type
Case MyGame_ChatMessage
'Execute code that unpacks and displays a chat message
Case MyGame_DataPacket
'Do Code that unpacks a data packet, and acts on it.
End Select 'Just keep on adding Case's for the constants defined earlier.
End If
End Sub