基本信息
源码名称:模拟操作91VPN句柄 自动换IP 源码
源码大小:0.14M
文件格式:.zip
开发语言:C#
更新时间:2015-08-05
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Win32ApiDemo
{
public partial class AutoChangeVpn : Form
{
public AutoChangeVpn()
{
InitializeComponent();
}
WinAPI.WindowInfo hwnd;//父句柄
private void btnGetIntPtr_Click(object sender, EventArgs e)
{
hwnd = WinAPI.GetProcessIdByName(txtProName.Text.Trim());
if (hwnd.hWnd != IntPtr.Zero)
{
txtHwnd.Text = hwnd.hWnd.ToString();
txtWinTitle.Text = hwnd.szWindowName;
txtClassName.Text = hwnd.szClassName;
listx.AddRange(wi.GetAllChildControls(hwnd.hWnd));//获取所有子元素
}
else
{
txtHwnd.Text = "获取句柄失败.!";
txtWinTitle.Text = "请确认[任务管理]";
txtClassName.Text = "可以看见进程名";
}
}
private void btnAutoLogin_Click(object sender, EventArgs e)
{
string uname = txtUser.Text.Trim();
string pwd = txtPass.Text.Trim();
if (hwnd.hWnd != IntPtr.Zero)
{
WinAPI wi = new WinAPI();
List<WinAPI.WindowInfo> listx = new List<WinAPI.WindowInfo>();
listx.AddRange(wi.GetAllChildControls(hwnd.hWnd));//获取所有子元素
List<WinAPI.WindowInfo> editlist = listx.FindAll(p => { return p.szClassName == "Edit"; });//获取所有Class为Edit
WinAPI.SetText(editlist[0].hWnd, uname);
WinAPI.SetText(editlist[1].hWnd, pwd);
List<WinAPI.WindowInfo> btnlist = listx.FindAll(p => { return p.szClassName == "Button"; });//获取所有Class为Button
for (int x = 0; x < btnlist.Count; x )
{
string btnName = WinAPI.GetText(btnlist[x].hWnd);
if (btnName == "登录")
{
WinAPI.SendMessage(btnlist[x].hWnd, WinAPI.BM_CLICK, 1, "0"); //点击登录
break;
}
}
}
}
private void btnConnect_Click(object sender, EventArgs e)
{
//再获得一次.不知道为啥来论坛看答案.
hwnd = WinAPI.GetProcessIdByName(txtProName.Text.Trim());
if (hwnd.hWnd != IntPtr.Zero)
{
List<WinAPI.WindowInfo> comblist = listx.FindAll(p => { return p.szClassName == "ComboBox"; });//获取所有Class为ComboBox
//这里不一定1和2就是国家等,详细判断代码可以用盒子辅助.
//当然,也可以通过位置或者数量的方式来判断到底因该拿哪一个句柄
bool setCountry= SetComb(comblist[1].hWnd, txtCountry.Text.Trim());
bool setRegion = SetComb(comblist[2].hWnd, txtRegion.Text.Trim());
//别乱删.你没看错,就是要执行两次.至于为啥.不懂来论坛提问.
setRegion = SetComb(comblist[2].hWnd, txtRegion.Text.Trim());
if (!setCountry || !setRegion)
{
MessageBox.Show("设置vpn链路失败.!");
return;
}
ClickButton(listx, "连接");
}
}
/// <summary>
/// 点击按钮
/// </summary>
/// <param name="listx"></param>
/// <param name="ButtonName"></param>
private void ClickButton(List<WinAPI.WindowInfo> listx,string ButtonName)
{
List<WinAPI.WindowInfo> btnlist = listx.FindAll(p => { return p.szClassName == "Button"; });//获取所有Class为Button
for (int x = 0; x < btnlist.Count; x )
{
string btnName = WinAPI.GetText(btnlist[x].hWnd);
if (btnName == ButtonName)
{
WinAPI.SendMessage(btnlist[x].hWnd, WinAPI.BM_CLICK, 1, "0"); //点击登录
break;
}
}
}
private bool SetComb(IntPtr xhwnd,string textstr)
{
int i = WinAPI.SendMessage(xhwnd, WinAPI.CB_FINDSTRING, -1, textstr);//获取需要选中的comb元素
WinAPI.SendMessage(xhwnd, WinAPI.CB_SHOWDROPDOWN, 1, "0");//展开
WinAPI.SendMessage(xhwnd, WinAPI.CB_SETCURSEL, i, "1");//设置选中
return i > 0 ? true : false;
}
WinAPI wi = new WinAPI();
List<WinAPI.WindowInfo> listx = new List<WinAPI.WindowInfo>();
private void AutoChangeVpn_Load(object sender, EventArgs e)
{
}
private void btnDispose_Click(object sender, EventArgs e)
{
ClickButton(listx, "断开");
}
}
}