制作托盘闪烁

using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections;
using System.IO;
using System.Xml;
using System.Text;
using System.Runtime.InteropServices;
namespace jy_PuDownform
{
 /// <summary>
 /// 实例化之后,调用

/// </summary>
 public class SetNotifyicon
 {
  public SetNotifyicon(System.Windows.Forms.NotifyIcon notify)
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
   _icon = notify.Icon;
   t = new System.Windows.Forms.Timer();
   t.Tick +=new EventHandler(t_Tick);
   t.Interval = 500;
   _notify = notify;
  }
  
  System.Collections.Hashtable HtMsg = new Hashtable();
  System.Windows.Forms.NotifyIcon _notify;
  private bool _isbicker = false;
  System.Drawing.Icon _icon;
  System.Windows.Forms.Timer t;
  System.Collections.Queue mReceiver = new Queue();
  Message Msg = new Message();
  /// <summary>
  /// 获取图标是否在闪烁
  /// </summary>
  public bool Isbicker
  {
   get{return _isbicker;}
  }
  public void m_ChangeIcon(System.Drawing.Icon icon)
  {
   _notify.Icon = icon;
   _icon = icon;
  }
  bool TM;
  /// <summary>
  /// 接收到信息时候闪烁,也可以用在登录时候
  /// </summary>
  /// <param name="icon"></param>
  /// <param name="ID"></param>
  public void m_Receive(System.Drawing.Icon icon,string ID,string msg,bool tm)
  {
   TM = tm;
   if(this.TM)
   {
    this._notify.Icon = icon;
   }
   if(!mReceiver.Contains(ID))
   {
    mReceiver.Enqueue(ID);
   }
   if(HtMsg.ContainsKey(ID))
   {
    ((Message)HtMsg[ID]).Msgs.Add(msg);
     }
   else
   {    
    //Msgs.Insert(0,Msg);
    Msg = new Message();
    Msg.UserID = ID;
    Msg.MsgContent = msg;
    Msg.Icon = icon;
   
    Msg.Msgs.Add(msg);
    HtMsg.Add(ID,Msg);
   }
   t.Enabled = true;
   _isbicker = true;
  }
  private void t_Tick(object send,EventArgs e)
  {
   if(mReceiver.Count>0)
   {
    if(this.TM)
    {
     if(!_notify.Icon.Equals(((Message)HtMsg[mReceiver.Peek().ToString()]).Icon))
     {
      _notify.Icon = ((Message)HtMsg[mReceiver.Peek().ToString()]).Icon;
     }
     return;
    }
    if(_notify.Icon.Equals(_icon))
    {
     _notify.Icon = ((Message)HtMsg[mReceiver.Peek().ToString()]).Icon;
    }
    else
    {
     _notify.Icon = _icon;
    }
   }
  }
  /// <summary>
  /// 获取第一个对话人,可以用在登录以后停止闪烁
  /// </summary>
  /// <returns></returns>
  public string m_GetUserID(out Message Msgs)
  {
   Msgs = null;
   if(mReceiver.Count>0)
   {
    Msgs = new Message();
    string temp = mReceiver.Dequeue().ToString();
    this.t.Enabled =false;
    this._isbicker = false;
    this._notify.Icon = _icon;
    Msgs.UserID = ((Message)HtMsg[temp]).UserID;
   
    Msgs.Icon = ((Message)HtMsg[temp]).Icon;
    Msgs.Msgs = (ArrayList)((Message)HtMsg[temp]).Msgs.Clone();
    ((Message)HtMsg[temp]).Msgs.Clear();
    if(mReceiver.Count>0)
    {
     this.t.Enabled =true;
     this._isbicker = true;
    }
    return temp;
   }
   return "";
  }
  public int MsgCount
  {
   get{return mReceiver.Count;}
  }
  public int MsgContByID(string ID)
  {
   return ((Message)HtMsg[ID]).Msgs.Count;
  }
  public string m_GetCode
  {
   get
   {
    if(mReceiver.Count>0)
    {
     string temp = mReceiver.Peek().ToString();
     return temp;
    }
    else
    {
     return "";
    }
   }
  }
 }

public class Message
 {
  public Message()
  {
  }
  public System.Drawing.Icon Icon;
  public string UserID;
  
  public string MsgContent;
  public System.Collections.ArrayList Msgs = new System.Collections.ArrayList();
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值