下面簡單用VB具體說明怎么調(diào)用它:
首先當(dāng)然是引用對象Messenger API Type Library了。
然后聲明一個對象MessengerAPI.Messenger。
Private WithEvents oMSN As MessengerAPI.Messenger |
我們需要的東西都在這里邊,簡單介紹幾個:
MyContacts:IMessengerContacts 對象
MyFriendlyName: 當(dāng)前的昵稱
MyGroups: IMessengerGroupss對象
MyPhoneNumber:返回電話號碼
MyProperty:現(xiàn)在沒有使用
MyServiceId :返回Service id應(yīng)該是{9b017612-c9f1-11d2-8d9f-0000f875c541}]
MyServiceName:返回Service name應(yīng)該是 .NET Messenger Service
MySigninName:返回當(dāng)前的簽名,eMail地址
MyStatus:返回當(dāng)前狀態(tài),MISTATUS枚舉值
其實本地屬性和通過PrimaryService得到的一樣
做幾個簡單的演示:
首先是登陸演示,使用MessengerAPI.Messenger的 SignIn 或者AutoSignin方法:
Public Sub SignIn(ByVal bAuto As Boolean, Optional ByVal sSignInName As String, Optional ByVal sPassword As String) On Error GoTo ErrorHandle If bAuto = True Then oMSN.AutoSignin Else ManualSignIn: oMSN.SignIn 0, sSignInName, sPassword End If Exit Sub ErrorHandle: Dim MConstants As MSGRConstants MConstants = err.Number If MConstants = MSGR_E_FAIL Then GoTo ManualSignIn ElseIf MConstants = MSGR_E_ALREADY_LOGGED_ON Then ’已經(jīng)登陸 End If End Sub |
獲取全部用戶列表:
通過Messenger的MyContacts對象(它是只讀的)
它其實就是一個IMessengerContacts對象,而IMessengerContacts類又是IMessengerContact類的一個集合,在IMessengerContact中保存聯(lián)系人信息。
因此可以這樣遍歷聯(lián)系人。
Dim oContacts As IMessengerContacts Dim oContact As IMessengerContact Dim iCount As Integer Dim i As Long Set oContacts = oMSN.MyContacts iCount = oContacts.Count For i = 0 To iCount - 1 Set oContact = MsgrContacts.Item List1.AddItem MsgrContact.FriendlyName & vbTab & "(" & getStatusDesc(MsgrContact.Status) & ")" Next |
getStatusDesc函數(shù)用來返回狀態(tài)文本描述:
Private Function getStatusDesc(eStatus As MISTATUS) As String Select Case eStatus Case MISTATUS_AWAY getStatusDesc = "走開了" Case MISTATUS_BE_RIGHT_BACK getStatusDesc = "馬上回來" Case MISTATUS_BUSY getStatusDesc = "在忙碌" Case MISTATUS_IDLE getStatusDesc = "在發(fā)呆" Case MISTATUS_INVISIBLE getStatusDesc = "隱身" Case MISTATUS_LOCAL_CONNECTING_TO_SERVER getStatusDesc = "正在鏈接服務(wù)器" Case MISTATUS_LOCAL_DISCONNECTING_FROM_SERVER getStatusDesc = "從服務(wù)器斷開" Case MISTATUS_LOCAL_FINDING_SERVER getStatusDesc = "正在搜索服務(wù)器" Case MISTATUS_LOCAL_SYNCHRONIZING_WITH_SERVER getStatusDesc = "正在和服務(wù)器同步" Case MISTATUS_OFFLINE getStatusDesc = "離線" Case MISTATUS_ON_THE_PHONE getStatusDesc = "在接電話" Case MISTATUS_ONLINE getStatusDesc = "在線" Case MISTATUS_OUT_TO_LUNCH getStatusDesc = "外出就餐" Case MISTATUS_UNKNOWN getStatusDesc = "未知" End Select End Function |
獲取組列表:
方法同獲取聯(lián)系人,只是換了一下對象.
Dim oGroups As IMessengerGroups Dim oGroup As IMessengerGroup Set oGroups = oMSN.MyGroups For Each oGroup In oGroups List1.AddItem oGroup.Name Next |
下面就是將組和用戶關(guān)聯(lián)起來:
明白上面的方法,這個很容易實現(xiàn),IMessengerGroup類的對象中含有IMessengerContact類對象的集合。
Dim oGroups As IMessengerGroups Dim oGroup As IMessengerGroup Dim oContacts As IMessengerContacts Dim oContact As IMessengerContact Set oGroups = oMSN.MyGroups For Each oGroup In oGroups Set oContacts = oGroup.Contacts For Each oContact In oContacts List1.AddItem oGroup.Name & " " & oContact.SigninName Next Next |
再介紹一下服務(wù):
也是用樣道理:
Dim oServices As IMessengerServices Dim oService As IMessengerService Set oServices = oMSN.Services Set oService = oServices.PrimaryService MsgBox oService.MyFriendlyName & getStatusDesc(oService.MyStatus) & oService.MySigninName & oService.ServiceId & oService.ServiceName |
我現(xiàn)在怎么覺得PrimaryService的意義不大,IMessengerServices中就一個PrimaryService可用,還是只讀的。
當(dāng)然各個對象可能還有一些相應(yīng)的方法就不多介紹,我介紹的這些通過對象瀏覽器就可以看明白,其中還有對象或成員我現(xiàn)在還沒學(xué)會使用,現(xiàn)在只是大致了解一下,我希望看到這篇文章的人也有了一點初步了解。