专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »VB教程 » msn怎么群发信息:用VB设计MSN信息群发软件Software »正文

msn怎么群发信息:用VB设计MSN信息群发软件Software

来源: 发布时间:星期五, 2008年12月26日 浏览:84次 评论:0
MSN是目前网络上广泛使用个即时信息交流工具(IM)笔者就常用它和同事或朋友联系但是在使用过程中发现缺乏个群发信息功能于是笔者寻思着自己编写个MSN信息群发软件Software在查阅了番资料的后终于写出来了下面大家和我起动手来自己做个MSN信息群发工具

  第步:新建个工程启动VB选择“文件”菜单“新建”子菜单新建个VB工程系统回自动添加个窗体,并且取名叫Form1

  第 2步:添加MSN接口引用点击VBIDE环境菜单中工程菜单在弹出下拉菜单中选择“引用(N)...”子菜单在弹出“引用”窗体中“可用引用”下拉列表中找到“Messenger API Type Library” 项将起前面钩打上然后关闭“引用”窗口

  第 3步:设置窗体添加Control控件首先在vb工程管理器中双击Form1打开窗体设计环境选中窗体将它Caption值改为“MSN消息群发”然后在窗体上添加Control控件并且设置其属性要添加Control控件信息见下表:

名称 类型 Caption属性
Label1 Label 群发对象:
Combo1 ComboBox
Check1 CheckBox 只发送在线
Label2 Label 消息内容:
Text1 TextBox

Command1 CommandButton 发送[&O]
Command2 CommandButton 退出[&X]

  添加完Control控件后调整其位置

第 4步:编写代码

Dim m_MSG As New MessengerAPI.Messenger 'MSNCom对象
Dim m_Groups As MessengerAPI.IMessengerGroups 'MSN中分组
Dim m_Group As MessengerAPI.IMessengerGroup 'MSN中组内容
Dim m_Contracts As MessengerAPI.IMessengerContacts 'MSN中所有好友信息
Dim m_Contract As MessengerAPI.IMessengerContact 'MSN中每个好友对象内容

Private Sub Command1_Click

 Dim i As Integer
 '检测需要发送信息是否合法
 If Trim(Text1.Text) = "" Then
  MsgBox "发送信息不能为空!", vbInformation, "提示"
  Text1.SetFocus
  Exit Sub
 End If
 '判断消息发送对象是全部好友还是某个组成员

 If Combo1.ListIndex = 0 Then
  Set m_Contracts = m_MSG.MyContacts
 Else
  Set m_Groups = m_MSG.MyGroups
  Set m_Group = m_Groups.Item(Combo1.ListIndex - 1)
  Set m_Contracts = m_Group.Contacts
 End If

'遍历要发送对象,发送信息

 For i = 0 To m_Contracts.Count - 1
  Set m_Contract = m_Contracts.Item(i)
  If Check1.Value = 1 Then
   If m_Contract.Status = 2 Then
    m_MSG.InstantMessage m_Contract '打开要发送好友窗体
    DoEvents
    SendKeys Text1.Text '写入信息
    DoEvents
    SendKeys "{enter}" '发送出信息
    DoEvents
    SendKeys "%{F4}" '关闭好友窗口
   End If
  Else
   m_MSG.InstantMessage m_Contract
   DoEvents
   SendKeys Text1.Text
   DoEvents
   SendKeys "{enter}"
   DoEvents
   SendKeys "%{F4}"
  End If
 Next i
 '成功发送完毕信息
 If MsgBox("发送完毕!是否清空消息?", vbInformation + vbYesNo, "提示") = vbYes Then
  Text1.Text = ""
  Text1.SetFocus
 Else
  Text1.SetFocus
 End If
End Sub

Private Sub Command2_Click
 Unload Me
End

End Sub

'化Control控件

Private Sub Form_Load
 Dim i As Integer
 '化发送对象下拉框
 Set m_Groups = m_MSG.MyGroups
 With Combo1
  .AddItem "全部组"
  For i = 0 To m_Groups.Count - 1
   Set m_Group = m_Groups.Item(i)
   .AddItem m_Group.Name
  Next i
  .ListIndex = 0
 End With
End Sub

'释放变量

Private Sub Form_Unload(Cancel As Integer)
 Set m_MSG = Nothing
 Set m_Groups = Nothing
 Set m_Group = Nothing
 Set m_Contracts = Nothing
 Set m_Contract = Nothing
End Sub

  第 5步:编译运行选择“文件”菜单生成“工程1.exe”菜单项个属于你MSN信息群发软件Software就完成了
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: