| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 764 人关注过本帖
标题:[求助]错那了?
只看楼主 加入收藏
比蜗牛快些
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:124
专家分:0
注 册:2007-4-16
收藏
 问题点数:0 回复次数:6 
[求助]错那了?

using System;
using System.Collections.Generic;
using System.Text;
using XihSolutions.DotMSN;
namespace Robot
{


public class Robot
{

private XihSolutions.DotMSN.Messenger messenger = new Messenger();

public Robot()
{
InitializeComponent();
// by default this example will emulate the official microsoft windows messenger client
messenger.Credentials.ClientID = "msmsgs@msnmsgr.com";
messenger.Credentials.ClientCode = "Q1P7W2E4J9R8U3S5";
//登录成功之后触发事件
messenger.NameserverProcessor.ConnectionEstablished += new EventHandler(NameserverProcessor_ConnectionEstablished);
messenger.Nameserver.SignedIn += new EventHandler(Nameserver_SignedIn);
messenger.ConversationCreated += new ConversationCreatedEventHandler(messenger_ConversationCreated);
}
//MSN机器人登录函数
private void login_Click(object sender, EventArgs e)
{
if (messenger.Connected)
{
SetStatus("Disconnecting from server");
messenger.Disconnect();
}
// set the credentials, this is ofcourse something every DotMSN program will need to
// implement.
messenger.Credentials.Account = account.Text;
messenger.Credentials.Password = password.Text;

// inform the user what is happening and try to connecto to the messenger network.
SetStatus("Connecting to server");
messenger.Connect();
// note that Messenger.Connect() will run in a seperate thread and return immediately.
// it will fire events that informs you about the status of the connection attempt.
// these events are registered in the constructor.
}
//Robot Form定时器执行函数
private void Timer_Tick(object sender, EventArgs e)
{
//遍历MSN机器人的所有好友
foreach (Contact contact in messenger.ContactList.All)
{
if (contact != null && contact.Online == true)
{
//实例化一个机器人与好友的对话
Conversation conversation = messenger.CreateConversation();
conversation.Invite(contact);//邀请好友参与对话
MyConversation agent = CreateMyConversation(conversation);//实例化一个对话处理
}
}
}
//对话处理的实例化(这个很关键)
/// <summary>
/// A delegate passed to Invoke in order to create the conversation form in the thread of the main form.
/// </summary>
private delegate MyConversation CreateConversationDelegate(Conversation conversation);

private MyConversation CreateMyConversation(Conversation conversation)
{
// create a new conversation. However do not show the window untill a message is received.
// for example, a conversation will be created when the remote client sends wants to send
// you a file. You don't want to show the conversation form in that case.
MyConversation agent = new MyConversation(conversation);

// do this to create the window handle. Otherwise we are not able to call Invoke() on the
// conversation form later.
//agent.Handle.ToInt32();

return agent;
}
//如果是第一次好友主动向MSN机器人发送消息,则调用
private void messenger_ConversationCreated(object sender, ConversationCreatedEventArgs e)
{
// check if the request is initiated remote or by this object
// if it is initiated remote then we have to create a conversation form. Otherwise the
// form is already created and we don't need to create another one.
if (e.Initiator == null)
{
// use the invoke method to create the form in the main thread
this.Invoke(new CreateConversationDelegate(CreateMyConversation), new object[] { e.Conversation });
}
}
//再来看看class MyConversation
private Conversation _conversation;

/// <summary>
/// The conversation object which is associated with the form.
/// </summary>
public Conversation Conversation
{
get { return _conversation; }
}
public void MyConversation(Conversation conversation)
{
_conversation = conversation;
//绑定事件,处理好友发送消息给MSN机器人
Conversation.Switchboard.TextMessageReceived += new TextMessageReceivedEventHandler(Switchboard_TextMessageReceived);
Conversation.Switchboard.SessionClosed += new SBChangedEventHandler(Switchboard_SessionClosed);
Conversation.Switchboard.ContactJoined += new ContactChangedEventHandler(Switchboard_ContactJoined);
Conversation.Switchboard.ContactLeft += new ContactChangedEventHandler(Switchboard_ContactLeft);
}
//MSN机器人给好友发送消息
public void SendInput(String inputMessage)
{
// check whether there is input
if (inputMessage.Length == 0) return;

// if there is no switchboard available, request a new switchboard session
if (Conversation.SwitchboardProcessor.Connected == false)
{
Conversation.Messenger.Nameserver.RequestSwitchboard(Conversation.Switchboard, this);
}

// note: you can add some code here to catch the event where the remote contact lefts due to being idle too long
// in that case Conversation.Switchboard.Contacts.Count equals 0.

TextMessage message = new TextMessage(inputMessage);

/* You can optionally change the message's font, charset, color here.
* For example:
* message.Color = Color.Red;
* message.Decorations = TextDecorations.Bold;
*/

Conversation.Switchboard.SendTextMessage(message);
}
private void Switchboard_ContactJoined(object sender, ContactEventArgs e)
{
SendInput("定时发送的消息");//实现MSN机器人向好友主动推送消息
}
private void PrintText(string name, string text)
{
if (text.ToLower().Equals("h"))
{
SendInput("帮助命令如下:\r输入“on”接收朋友信息\r输入“off”停止接收朋友信息\r输入“@用户名+空格+内容”给某人发送信息\r输入“*用户名+空格+内容”给某人发送悄悄话\r输入“find+空格+关键字”查询用户\r输入“add+空格+用户名”添加某人为好友\r输入其他信息则发送到有趣吧。");
}
}
//MSN机器人接收消息
private void Switchboard_TextMessageReceived(object sender, TextMessageEventArgs e)
{
PrintText(e.Sender.Name, e.Message.Text);
}
}
}





错误 1 找不到类型或命名空间名称“MyConversation”(是否缺少 using 指令或程序集引用?) C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\ClassLibrary2\ClassLibrary2\Class1.cs 64 26 ClassLibrary2
错误 2 找不到类型或命名空间名称“MyConversation”(是否缺少 using 指令或程序集引用?) C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\ClassLibrary2\ClassLibrary2\Class1.cs 66 17 ClassLibrary2

我错在那儿了?
DotMSN2.0在http://www.xihsolutions.net/dotmsn/download.html可以下载。
跪求了,不完成这个世界上又要多一个可怜的失业者了。

搜索更多相关主题的帖子: microsoft windows messenger default official 
2007-11-08 16:55
a464108502
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-11-5
收藏
得分:0 
我认为上面不是说了,“MyConversation”应该是类型。
怎么引用到它的,你自己好好找找吧

2007-11-08 17:56
比蜗牛快些
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:124
专家分:0
注 册:2007-4-16
收藏
得分:0 

public MyConversation(Conversation conversation)
{
_conversation = conversation;
//绑定事件,处理好友发送消息给MSN机器人
Conversation.Switchboard.TextMessageReceived += new TextMessageReceivedEventHandler(Switchboard_TextMessageReceived);
Conversation.Switchboard.SessionClosed += new SBChangedEventHandler(Switchboard_SessionClosed);
Conversation.Switchboard.ContactJoined += new ContactChangedEventHandler(Switchboard_ContactJoined);
Conversation.Switchboard.ContactLeft += new ContactChangedEventHandler(Switchboard_ContactLeft);
}

去了void就不报上两个错误,但是就报

错误 1 类、结构或接口方法必须有返回类型 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\ClassLibrary2\ClassLibrary2\Class1.cs 102 16 ClassLibrary2


地球人的缺点与恶习集一身,小心感染不良恶习
2007-11-09 08:57
比蜗牛快些
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:124
专家分:0
注 册:2007-4-16
收藏
得分:0 

有什么解决方案啊,那位大侠帮帮忙啊。


地球人的缺点与恶习集一身,小心感染不良恶习
2007-11-09 09:39
a464108502
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-11-5
收藏
得分:0 
不知道你“MyConversation”用来做什么,或他有什么功能,象这个还是要自己慢慢琢磨。
只看上面的文件也看不出什么来。
学历有限啊

2007-11-09 16:42
guoxhvip
Rank: 8Rank: 8
来 自:聖西羅南看臺
等 级:贵宾
威 望:44
帖 子:4052
专家分:135
注 册:2006-10-8
收藏
得分:0 
委托返回类型MyConversation好象没在你的程序中看见
就算加上你下面的代码也不行,你下面的代码是个什么?你这样写出来像是构造方法

愛生活 && 愛編程
2007-11-11 01:31
卡卡艾
Rank: 6Rank: 6
等 级:贵宾
威 望:22
帖 子:672
专家分:0
注 册:2007-4-3
收藏
得分:0 
错误指在哪句上?红色表明一下看看.

革命尚未成功,同志仍需努力-----+++
2007-11-11 08:33
快速回复:[求助]错那了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032976 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved