using System;
using System.IO;
using System.Net;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private bool m_bFlag = true;
//根据Url地址得到网页的HTML源码
private string GetWebContent(string Url)
{
string strResult = "";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
//声明一个HttpWebRequest请求
request.Timeout = 30000;
//设置连接超时时间
request.Headers.Set("Pragma", "no-cache");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamReceive = response.GetResponseStream();
Encoding encoding = Encoding.GetEncoding("gb2312");
StreamReader streamReader = new StreamReader(streamReceive, encoding);
strResult = streamReader.ReadToEnd();
streamReader.Close();
}
catch
{
MessageBox.Show("出错");
}
return strResult;
}
public Form1()
{
InitializeComponent();
this.notifyIcon1.Icon = new Icon("1.ico");
this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
this.timer2.Enabled = true;
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
}
private void Form1_SizeChanged(object sender, System.EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Hide();
}
}
//关闭
private void toolStripMenuItem4_Click(object sender, System.EventArgs e)
{
this.Close();
}
//显示
private void toolStripMenuItem3_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Show();
this.WindowState = FormWindowState.Normal;
this.Activate();
this.timer1.Stop();
this.notifyIcon1.Icon = new Icon("1.ico");
}
}
//抓
private void timer2_Tick(object sender, System.EventArgs e)
{
//抓取数据
string Url = "http://192.168.2.27:91/admin/Admin_User.asp";
string strWebContent = GetWebContent(Url);
FileStream fs = new FileStream(@"1.txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
string strData = sr.ReadToEnd();
sr.Close();
fs.Close();
if (strWebContent != strData)
{
this.webBrowser1.Refresh();
this.timer1.Start();
this.timer1.Tick += new EventHandler(this.timer1_Tick);
StreamWriter sw = new StreamWriter("1.txt");
sw.Write(strWebContent);
sw.Close();
}
}
//闪
private void timer1_Tick(object sender, System.EventArgs e)
{
if (m_bFlag)
{
this.notifyIcon1.Icon = new Icon("2.ico");
m_bFlag = false;
}
else
{
this.notifyIcon1.Icon = new Icon("1.ico");
m_bFlag = true;
}
}
}
}