eventsclass.cs

来自「进程间通信精华资料,包括好多源码,和文章,都是个人收集的.主要是vc和c#方面的」· CS 代码 · 共 142 行

CS
142
字号
using System;
using System.Collections;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using ChatMediator;

namespace ChatClient
{
	/// <summary>
	/// Summary description for EventsClass.
	/// </summary>
	/// 

	public delegate void GetClientsList(IClientImplement clientObject);
	public delegate void WelComeMessage(IClientImplement clientObject);
	public delegate void GetMessageFromOthers(IClientImplement clientObject);
	public delegate void UserLeftChat(IClientImplement clientObject);
	
	[Serializable]
	public class EventsClass : EventsManager
	{
		private string userName = string.Empty;
		private string msg = string.Empty;
		private ArrayList clientList = null;
		private string receiver = string.Empty;

		public event GetClientsList ClientListHandler;
		public event WelComeMessage WelComeHandler;
		public event GetMessageFromOthers GetMessageFromOthersHandler;
		public event UserLeftChat UserLeftHandler;

		public EventsClass()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public override System.Collections.ArrayList ClientList
		{
			get
			{
				return this.clientList;
			}
			set
			{
				this.clientList = value;
			}
		}

		public override string UserName
		{
			get
			{
				return this.userName;
			}
			set
			{
				this.userName = value;
			}
		}

		public override string Message
		{
			get
			{
				return this.msg;
			}
			set
			{
				this.msg = value;
			}
		}

		public override string ReceiverName
		{
			get
			{
				return this.receiver;
			}
			set
			{
				this.receiver = value;
			}
		}

		public override void SendMessageTome(IClientImplement clientObject)
		{
			if (this.GetMessageFromOthersHandler != null)
			{
				this.GetMessageFromOthersHandler(clientObject);
			}
		}

		public override void SendWelcomeMessageTome(IClientImplement clientObject)
		{
			if (this.ClientListHandler != null)
			{
				this.ClientListHandler(clientObject);
			}
			if (this.WelComeHandler != null)
			{
				this.WelComeHandler(clientObject);
			}
		}

		public override void UserLeft(IClientImplement clientObject)
		{
			if (this.ClientListHandler != null)
			{
				this.ClientListHandler(clientObject);
			}
			if (this.UserLeftHandler != null)
			{
				this.UserLeftHandler(clientObject);
			}			
		}
	}

	public class SafeNativeMethods
	{	
		[return : MarshalAs(UnmanagedType.Bool)]
		[DllImport("WinMM.dll")]
		private static extern bool PlaySound(string fname, int Mod, int flag);

		// these are the SoundFlags we are using here, check mmsystem.h for more
		public const int SendAsync    = 0x0001;     // play asynchronously
		public const int SendFileName = 0x00020000; // use file name
		public const int SendPurge    = 0x0040;     // purge non-static events

		public static void Play(string fileName, int soundFlags)
		{
			PlaySound(fileName, 0, soundFlags);
		}

		public static void StopPlay()
		{
			PlaySound(null, 0, SendPurge);
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?