製作托盤閃爍

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();
 }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章