using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;
using US.Browser.IE.BLL;
using System.Threading;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using System.IO;
using System.Diagnostics;
using System.Configuration;
using System.Web.Configuration;
using Shell32;
namespace US.Browser.IE
{
///
/// 应用程序
///
public partial class StaticClass : Form
{
#region 变量区域
public static StaticClass _USE; //应用启动区域
RespondWeb _UVE; //webbrower开发功能区
USMain _UM;
private static Popup _UPE;//广告页面
public static string _UST;//启动程序的方式
private Respond_setting _URE;//浏览器系统设置功能区域
private static Thread th = null;//线程
public static string ver = FileVersionInfo.GetVersionInfo(System.Windows.Forms.Application.ExecutablePath).FileVersion;//当前版本
public static News _UNE;//消息
public static string UCON = System.Configuration.ConfigurationSettings.AppSettings["type"];//Config设置
static System.Windows.Forms.Timer _UDT = null; static Icon ic; static Icon[] aic; static string icoscr = string.Empty; static bool tf;
public static MouseEventHandler _ume;
#endregion
#region 生成应用程序
///
/// 应用程序初始化
///
///
///
public static StaticClass getI(string UST)
{
_USE = new StaticClass(); _UST = UST;
_USE.StaticClass_Load(); return _USE;
}
///
/// 多窗口
///
///
///
public static StaticClass Restart(string UTP)
{
return StaticClass.getI(UTP);
}
///
/// 实例化应用程序
///
///
public static StaticClass getInstance()
{
if (BLL.USIE.isnet())
{
if (_USE == null) { _USE = new StaticClass(); }//生成任务托盘
else { _USE.CreateMain(false); }
return _USE;
}
return null;
}
///
/// 无参数构造
///
public StaticClass()
{
InitializeComponent(); //实例化右键菜单
Control.CheckForIllegalCrossThreadCalls = false;
}
///
/// 托盘加载完毕启动
///
///
///
private void StaticClass_Load()
{
bool _UTF = _UST.IndexOf("-background") != -1; _URE = new Respond_setting(); //浏览器设置区域
this._UM = CreateMain(_UTF); _UPE = new Popup(_UM); UpdateCue.NewUpCF(_USE); _UNE = new News(_UM._USY);
_UVE = new RespondWeb(null, _UM._USY); System.Windows.Forms.Timer _UTM = new System.Windows.Forms.Timer();
_UTM.Tick += new EventHandler(delegate(object sender, EventArgs e) { _UTM.Stop(); _UTM.Dispose(); _UPE.Show(); });
_UTM.Interval = 600000; _UTM.Start();
}
///
/// 创建主窗体
///
///
public USMain CreateMain(bool UTF)
{
USMain _UM = new USMain();
System.Windows.Forms.Timer _UTM = new System.Windows.Forms.Timer(); _UTM.Tick += new EventHandler(delegate(object sender, EventArgs e) //窗体加载等待
{
aic = new Icon[] { new System.Drawing.Icon(Application.StartupPath + "//logo.ico"), new System.Drawing.Icon(Application.StartupPath + "//head.ico") };
StaticClass.postUseBE(); _UTM.Stop(); _UTM.Dispose(); _UTM = null; if (!UTF && BLL.USIE.isnet()) { _UM.Show(); }
});
_UTM.Interval = 1; _UTM.Start(); return _UM;
}
///
/// 浏览器关闭
///
///
///
void StaticClass_Disposed(object sender, System.EventArgs e)
{
Process _UPE = System.Diagnostics.Process.GetCurrentProcess();
BLL.WindowHWND.freem(); this.USIcon.Dispose(); this.IconMenu.Dispose();
_UPE.Kill(); _UPE.Close(); _UPE.Dispose();
}
#endregion
#region 托盘闪烁使用
///
/// 闪烁
///
public static void _twstart(string img, string tf, string ue, WebBrowser wb, RespondWeb rf)
{
sjxxs(tf, ue, wb, rf);
if (_UDT == null) { icoscr = img; _traytwinkle(img); }
else if (ic == null || icoscr != img) { if (ic != null) { ic.Dispose(); } icoscr = img; ic = geticon(img); }
}
///
/// 关闭闪烁
///
public static void _twstop()
{
if (_UDT != null) { _UDT.Stop(); _UDT.Dispose(); } _UDT = null; icoscr = string.Empty;
if (_USE.USIcon.Icon != aic[0]) { _USE.USIcon.Icon = aic[0]; } if (ic != null) { ic.Dispose(); ic = null; }
}
///
/// 闪烁开始
///
///
public static void _traytwinkle(object img)
{
_UDT = new System.Windows.Forms.Timer(); tf = true; string iimg = (string)img;
if (ic != null) { ic.Dispose(); } ic = geticon(iimg); ic = ic == null ? aic[1] : ic; _USE.USIcon.Text = "查看消息";
_UDT.Tick += new EventHandler(_UDT_Tick); _UDT.Interval = 800; _UDT.Start();
}
///
/// 闪烁变化
///
///
///
static void _UDT_Tick(object sender, EventArgs e)
{
Icon _ic = tf ? ic : aic[0];
if (_ic == null) { _twstop(); }
else { _USE.USIcon.Icon = _ic; tf = !tf; }
}
///
/// 闪烁按钮添加事件
///
public static void sjxxs(string tf, string ue, WebBrowser wb, RespondWeb rf)
{
NotifyIcon icn = StaticClass._USE.USIcon;
icn.MouseClick -= _ume; //取消相同事件
_ume = new MouseEventHandler(delegate(object sender, MouseEventArgs me)
{
if (me.Button == MouseButtons.Left)
{
icn.MouseClick -= _ume; icn.Text = "云端";
rf.OpenLook(new object[] { tf, ue }, wb); StaticClass._twstop();
}
});
icn.MouseClick += _ume; //添加事件
}
///
/// 获取icon
///
///
///
public static Icon geticon(string img)
{
Icon ic = null;
try
{
System.Net.HttpWebRequest webrq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(img);
System.Net.HttpWebResponse webres = (System.Net.HttpWebResponse)webrq.GetResponse();
if (webres.StatusCode == System.Net.HttpStatusCode.OK && webres.ContentLength > 0)
{
using (Stream stream = webres.GetResponseStream())
{
using (Image image = Image.FromStream(stream))
{
using (Bitmap bmp = new Bitmap(image, new Size(16, 16)))
{
ic = Icon.FromHandle(bmp.GetHicon());
bmp.Dispose();
}
image.Clone(); image.Dispose();
}
stream.Close(); stream.Dispose();
}
}
webrq.Abort(); webres.Close();
}
catch (Exception e) { BLL.WindowHWND.freem(); }
return ic;
}
#endregion
#region 托盘点击
///
/// 点击查看
///
public void Show_Click()
{
if (BLL.USIE.isnet())
{
int i; List