实例介绍
【实例截图】

【核心代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Threading;
using mshtml;
using System.Net;
using System.Runtime.InteropServices;
namespace WebClick_Tool
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
//RegSetting.RegeditKeyDel("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\5.0\\User Agent", new List<string>() {"ddd","默认" });
DisMes = new MsgLableTxt(LbMes);//建立委托
Enb = new EnbBt(Ebbt);
Bclick = new BtClick(button2_Click);
FormMian = this;
KeyPress_o.Hook_Start();
timer1.Start();
}
/// <summary>
/// 停止
/// </summary>
public static bool StopAll = false;
/// <summary>
/// 窗体对象
/// </summary>
public static Form FormMian = null;
/// <summary>
/// 浏览器配置
/// </summary>
List<string> BroswerConfig = new List<string>();
/// <summary>
/// 关键词列表
/// </summary>
List<string> GjcList = new List<string>();
/// <summary>
/// 浏览器环境
/// </summary>
List<List<string>> BrowserEnvironment = new List<List<string>>();
/// <summary>
/// 代理缓存
/// </summary>
public static List<string> ProxyList = new List<string>();
public static List<string> ProxyList_Old = new List<string>();
/// <summary>
/// 使用旧还是新
/// </summary>
public static bool NowRead = false;
/// <summary>
/// 声明委托类
/// </summary>
/// <param name="MsgStr"></param>
public delegate void MsgLableTxt(string MsgStr);
/// <summary>
/// 定义委托
/// </summary>
public static MsgLableTxt DisMes;
/// <summary>
/// 声明委托类
/// </summary>
/// <param name="MsgStr"></param>
public delegate void EnbBt();
/// <summary>
/// 定义委托
/// </summary>
public static EnbBt Enb;
/// <summary>
/// 声明委托类
/// </summary>
/// <param name="MsgStr"></param>
public delegate void BtClick(object sender, EventArgs e);
/// <summary>
/// 定义委托
/// </summary>
public static BtClick Bclick;
ThreadWork Tw;
private void LbMes(string Msg)
{
if (label1.InvokeRequired)
{
this.Invoke(DisMes, Msg);
}
else
label1.Text = Msg;
}
private void Ebbt()
{
if (button1.InvokeRequired)
{
this.Invoke(Enb);
}
else
button1.Enabled = true;
if (button2.InvokeRequired)
{
this.Invoke(Enb);
}
else
button2.Enabled = true;
}
/// <summary>
/// 加载配置
/// </summary>
private void button1_Click(object sender, EventArgs e)
{
timer1.Stop();
StreamReader Sr = new StreamReader(Application.StartupPath "\\Config.txt",Encoding.Default);
BroswerConfig.AddRange(Sr.ReadToEnd().Replace("\r\n", "^").Split('^'));
Sr = new StreamReader(Application.StartupPath "\\待点击关键词.txt", Encoding.Default);
GjcList.AddRange(Sr.ReadToEnd().Replace("\r\n", "^").Split('^'));
Sr = new StreamReader(Application.StartupPath "\\BrowserEnvironment.txt", Encoding.Default);
string line = "";
string[] Lines=null;
while ((line = Sr.ReadLine()) != null)
{
if (line.Contains("Mozilla/") && line.Contains("Windows NT"))
{
line = line.Replace(")", ";");
line = line.Replace("(", ";");
Lines=line.Split(';');
if (Lines.Length > 2)
{
BrowserEnvironment.Add(new List<string>() { });
int TempInt = BrowserEnvironment.Count - 1;
for (int i = 0; i < Lines.Length - 1; i )
{
BrowserEnvironment[TempInt].Add(Lines[i].Trim());
}
}
}
}
Sr.Close();
if (BroswerConfig.Count > 4)
{
label1.Text = "加载浏览器设置完成...";
}
}
/// <summary>
/// 开始点击
/// </summary>
private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();
try
{
SetPenetrate();
StopAll = false;
Tw = new ThreadWork(BroswerConfig, BrowserEnvironment, GjcList);
button1.Enabled = false;
button2.Enabled = false;
Tw.Work_Thread.Start();
Tw.out_Work_Thread.Start();
}
catch { MessageBox.Show("配置错误!"); }
}
/// <summary>
/// 更新代理
/// </summary>
/// <returns></returns>
public static bool GetProxy()
{
try
{
string IpStr = GetPage("http://jipin.aliapp.com/ip.txt", "", Encoding.UTF8);
if (IpStr.Replace("\r\n", "").Trim() != "" && IpStr.Contains("\r\n"))
{
ProxyList_Old.Clear();
if (ProxyList.Count != 0)
{
ProxyList_Old = ProxyList.GetRange(0, ProxyList.Count);
}
NowRead = true;
ProxyList.Clear();
ProxyList.AddRange(IpStr.Replace("\r\n", "*").Split('*'));
NowRead = false;
}
else
{
return false;
}
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 获取源代码
/// </summary>
/// <param name="url"></param>
/// <param name="encoding"></param>
/// <returns></returns>
public static string GetPage(string url, string PointStr, Encoding Ec)
{
HttpWebRequest request = null;
HttpWebResponse response = null;
StreamReader reader = null;
try
{
request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = true;
request.AllowWriteStreamBuffering = true;
if (PointStr != "")
{
//设置代理
WebProxy proxy = new WebProxy();
proxy.Address = new Uri("http://" PointStr);
request.UseDefaultCredentials = true;
request.Proxy = proxy;
}
request.Timeout = 10000;
response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK &&
response.ContentLength < 1024 * 1024)
{
reader = new StreamReader(response.GetResponseStream(), Ec);
string html = reader.ReadToEnd();
return html;
}
}
catch
{
return "";
}
finally
{
if (response != null)
{
response.Close();
response = null;
}
if (reader != null)
reader.Close();
if (request != null)
request = null;
}
return "";
}
private void MainForm_Load(object sender, EventArgs e)
{
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Size.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Size.Height - this.Height);
}
int time = 5000;
bool gj = false;
private void timer1_Tick(object sender, EventArgs e)
{
if (StopAll)
{
label1.Text = "停止...";
timer1.Stop();
}
if (!gj)
label1.Text = (time / 1000.0).ToString("0.00") "秒后自动加载配置! F2停止...";
else
label1.Text = (time / 1000.0).ToString("0.00") "秒后自动开始! F2停止...";
time -= 100;
if (time <= 0 && !gj)
{
gj = true;
button1_Click(null, null);
timer1.Start();
time = 5000;
}
if (time <= 0 && gj)
{
timer1.Stop();
button2_Click(null, null);
}
}
#region 窗体鼠标穿透
private const uint WS_EX_LAYERED = 0x80000;
private const int WS_EX_TRANSPARENT = 0x20;
private const int GWL_STYLE = (-16);
private const int GWL_EXSTYLE = (-20);
private const int LWA_ALPHA = 0;
[DllImport("user32", EntryPoint = "SetWindowLong")]
private static extern uint SetWindowLong(
IntPtr hwnd,
int nIndex,
uint dwNewLong
);
[DllImport("user32", EntryPoint = "GetWindowLong")]
private static extern uint GetWindowLong(
IntPtr hwnd,
int nIndex
);
[DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]
private static extern int SetLayeredWindowAttributes(
IntPtr hwnd,
int crKey,
int bAlpha,
int dwFlags
);
/// <summary>
/// 设置窗体具有鼠标穿透效果
/// </summary>
public void SetPenetrate()
{
this.TopMost = true;
GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);
SetLayeredWindowAttributes(this.Handle, 0, 100, LWA_ALPHA);
}
#endregion
}
}
标签: 网络
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论