如何获得MSN的联系人信息(100分)

  • 主题发起人 主题发起人 Avalon
  • 开始时间 开始时间
给你提供点信息,帮你顶起<br>关于MSN 6的一些API介绍 <br>2004年6月11日 13:10 <br>了解这方面内容的起因是早上有位朋友让我看一段关于MSN开发程序,现在无法运行,我打开工程发现是针对4.7编写的,而他的计算机安装的6,2,因为我也用6.2所以我在VB中查看了一下,发现是缺少Messenger Type Library。但是多了Messenger API Type Library,可能是做为Messenger Type Library的替代,但是发现它的功能不如以前的Messenger Type Library 全面,起码我现在就发现它不能修改本地的MyFriendlyName,不明白为什么把它弄成只读的,MyStatus是可写。<br><br>下面简单用VB距离说明怎么调用它:<br><br>首先当然是引用对象Messenger API Type Library了。<br><br>然后声明一个对象MessengerAPI.Messenger<br>Private WithEvents oMSN As MessengerAPI.Messenger<br><br>我们需要的东西都在这里边,简单介绍几个:<br>MyContacts:IMessengerContacts 对象<br>MyFriendlyName: 当前的昵称<br>MyGroups: IMessengerGroupss对象<br>MyPhoneNumber:返回电话号码<br>MyProperty:现在没有使用<br>MyServiceId :返回Service id应该是{9b017612-c9f1-11d2-8d9f-0000f875c541}]<br>MyServiceName:返回Service name应该是 .NET Messenger Service<br>MySigninName:返回当前的签名,eMail地址<br>MyStatus:返回当前状态,MISTATUS枚举值<br>其实本地属性和通过PrimaryService得到的一样<br><br>做几个简单的演示:<br>首先是登陆演示,使用MessengerAPI.Messenger的 SignIn 或者AutoSignin方法:<br>Public Sub SignIn(ByVal bAuto As Boolean, Optional ByVal sSignInName As String, Optional ByVal sPassword As String)<br>On Error GoTo ErrorHandle<br> &nbsp; If bAuto = True Then<br> &nbsp; &nbsp; &nbsp; oMSN.AutoSignin<br> &nbsp; Else<br>ManualSignIn:<br> &nbsp; &nbsp; &nbsp; oMSN.SignIn 0, sSignInName, sPassword<br> &nbsp; End If<br><br> &nbsp; Exit Sub<br>ErrorHandle:<br>Dim MConstants As MSGRConstants<br> &nbsp; MConstants = err.Number<br> &nbsp; If MConstants = MSGR_E_FAIL Then<br> &nbsp; &nbsp; &nbsp; GoTo ManualSignIn<br> &nbsp; ElseIf MConstants = MSGR_E_ALREADY_LOGGED_ON Then<br> &nbsp; &nbsp; &nbsp; '已经登陆<br> &nbsp; End If<br>End Sub<br><br>获取全部用户列表:<br>通过Messenger的MyContacts对象(它是只读的)<br>它其实就是一个IMessengerContacts对象,而IMessengerContacts类又是IMessengerContact类的一个集合,在IMessengerContact中保存联系人信息。<br>因此可以这样遍历联系人。<br>Dim oContacts As IMessengerContacts<br>Dim oContact As IMessengerContact<br>Dim iCount As Integer<br>Dim i As Long<br>Set oContacts = oMSN.MyContacts<br>iCount = oContacts.Count<br>For i = 0 To iCount - 1<br> &nbsp;Set oContact = MsgrContacts.Item<br> &nbsp; &nbsp;List1.AddItem MsgrContact.FriendlyName & vbTab & &quot;(&quot; & getStatusDesc(MsgrContact.Status) & &quot;)&quot;<br>Next<br><br>getStatusDesc函数用来返回状态文本描述:<br>Private Function getStatusDesc(eStatus As MISTATUS) As String<br> &nbsp; &nbsp;Select Case eStatus<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_AWAY<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getStatusDesc = &quot;走开了&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_BE_RIGHT_BACK<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getStatusDesc = &quot;马上回来&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_BUSY<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getStatusDesc = &quot;在忙碌&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_IDLE<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getStatusDesc = &quot;在发呆&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_INVISIBLE<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getStatusDesc = &quot;隐身&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_LOCAL_CONNECTING_TO_SERVER<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getStatusDesc = &quot;正在链接服务器&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_LOCAL_DISCONNECTING_FROM_SERVER<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getStatusDesc = &quot;从服务器断开&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_LOCAL_FINDING_SERVER<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getStatusDesc = &quot;正在搜索服务器&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_LOCAL_SYNCHRONIZING_WITH_SERVER<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getStatusDesc = &quot;正在和服务器同步&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_OFFLINE<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getStatusDesc = &quot;离线&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_ON_THE_PHONE<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getStatusDesc = &quot;在接电话&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_ONLINE<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getStatusDesc = &quot;在线&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;Case MISTATUS_OUT_TO_LUNCH<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getStatusDesc = &quot;外出就餐&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp; Case MISTATUS_UNKNOWN<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;getStatusDesc = &quot;未知&quot;<br> &nbsp; &nbsp;End Select<br> &nbsp; &nbsp;<br>End Function<br><br>获取组列表:<br>方法同获取联系人,只是换了一下对象.<br>Dim oGroups As IMessengerGroups<br>Dim oGroup As IMessengerGroup<br> &nbsp;Set oGroups = oMSN.MyGroups<br> &nbsp;For Each oGroup In oGroups<br> &nbsp; &nbsp; &nbsp;List1.AddItem oGroup.Name<br> &nbsp;Next<br> <br> 下面就是将组和用户关联起来:<br> 明白上面的方法,这个很容易实现,IMessengerGroup类的对象中含有IMessengerContact类对象的集合。<br> Dim oGroups As IMessengerGroups<br>Dim oGroup As IMessengerGroup<br>Dim oContacts As IMessengerContacts<br>Dim oContact As IMessengerContact<br> &nbsp;Set oGroups = oMSN.MyGroups<br> &nbsp;For Each oGroup In oGroups<br> &nbsp; &nbsp; &nbsp;Set oContacts = oGroup.Contacts<br> &nbsp; &nbsp; &nbsp;For Each oContact In oContacts<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List1.AddItem oGroup.Name & &quot; &quot; & oContact.SigninName<br> &nbsp; &nbsp; &nbsp;Next<br> &nbsp;Next <br> &nbsp;在介绍一下服务:<br> &nbsp;也是用样道理:<br> &nbsp;Dim oServices As IMessengerServices<br>Dim oService As IMessengerService<br> &nbsp;Set oServices = oMSN.Services<br> &nbsp;Set oService = oServices.PrimaryService<br> &nbsp;MsgBox oService.MyFriendlyName & getStatusDesc(oService.MyStatus) & oService.MySigninName & oService.ServiceId & oService.ServiceName<br><br>我现在怎么觉得PrimaryService的意义不大,IMessengerServices中就一个PrimaryService可用,还是只读的。<br>当然各个对象可能还有一些相应的方法就不多介绍,我介绍的这些通过对象浏览器就可以看明白,其中还有对象或成员我现在还没学会使用,现在只是大致了解一下,我希望看到这篇文章的人也有了一点初步了解。
 
求delphi的
 
帮顶! <br><br>http://www.source520.com <br><br>站长开发推广同盟 站长朋友的终极驿站 <br>同时拥有海量源码电子经典书籍下载 <br><br>http://www.source520.com/search/search.asp <br><br>&quot;编程.站长&quot;论坛搜索引擎-----为中国站长注入动力!
 
我来拿分,谢谢.
 
多人接受答案了。
 
后退
顶部