基本信息
源码名称:WinApi获取其他程序的数据
源码大小:0.09M
文件格式:.zip
开发语言:C#
更新时间:2015-11-25
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 10 元×
微信扫码支付:10 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace DataGetApp { public partial class Form1 : Form { protected IntPtr TargetWin; protected int TargetPid = 0; protected MyProcess mp = new MyProcess(); protected MyWindow mw = new MyWindow(); public Form1() { InitializeComponent(); } /// <summary> /// 隐藏目标窗体 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnHideWin_Click(object sender, EventArgs e) { if (TargetWin == IntPtr.Zero) { Process[] pros = Process.GetProcesses(); foreach (Process pro in pros) { if (pro.ProcessName.Equals("SuoyaPos")) { TargetWin = mp.GetMainWindowHandle(pro.Id); } } } MyWindow.ShowWindow(TargetWin, 2); } /// <summary> /// 最大化显示目标窗体 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnShowWin_Click(object sender, EventArgs e) { if (TargetWin == IntPtr.Zero) { Process[] pros = Process.GetProcesses(); foreach (Process pro in pros) { if (pro.ProcessName.Equals("SuoyaPos")) { TargetWin = mp.GetMainWindowHandle(pro.Id); } } } MyWindow.ShowWindow(TargetWin, 3); } /// <summary> /// 关闭窗体 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCloseWin_Click(object sender, EventArgs e) { if (TargetWin == IntPtr.Zero) { Process[] pros = Process.GetProcesses(); foreach (Process pro in pros) { if (pro.ProcessName.Equals("SuoyaPos")) { TargetWin = mp.GetMainWindowHandle(pro.Id); } } } MyWindow.ShowWindow(TargetWin, 0); } private int processid; private void btnGetData_Click(object sender, EventArgs e) { string processname = txtProcessName.Text.ToString().Trim(); if (string.IsNullOrEmpty(processname)) { MessageBox.Show("进程名不能为空!"); return; } lstControls.Items.Clear(); //if (TargetWin == IntPtr.Zero) //{ Process[] pros = Process.GetProcesses(); foreach (Process pro in pros) { if (pro.ProcessName.Equals(processname)) { TargetWin = mp.GetMainWindowHandle(pro.Id); processid = pro.Id; } } //} List<IntPtr> controlHandleList = mw.GetChildControlsHandle(TargetWin); List<ControlModel> ctrmodellist = new List<ControlModel>(); int i = 0; foreach (IntPtr ctrhandle in controlHandleList) { GetControlsText(ctrhandle, ref ctrmodellist); } ctrmodellist = ctrmodellist.Distinct(new PropertyComparer<ControlModel>("ctrhandleid")).ToList(); foreach (ControlModel cm in ctrmodellist) { i ; ListViewItem lvItem = new ListViewItem(); lvItem.SubItems[0].Text = i.ToString(); lvItem.SubItems.Add(cm.ctrhandleid.ToString()); lvItem.SubItems.Add(cm.ctrname); lvItem.SubItems.Add(cm.ctrtype); lvItem.SubItems.Add(cm.ctrvalue); this.lstControls.Items.Add(lvItem); } } private void GetControlsText(IntPtr ctrHandle, ref List<ControlModel> refctrlist) { ControlModel ctrmodel = new ControlModel(); string ctrtext = ""; #region 根据句柄获取控件属性 string ctrclass = MyControl.GetControlClass(ctrHandle); if (ctrclass.ToUpper().Contains("EDIT") || ctrclass.Contains("BUTTON") || ctrclass.Contains("STATIC")) { ctrtext = MyControl.GetControlTitle(ctrHandle); ctrmodel.ctrhandleid = ctrHandle.ToInt32(); ctrmodel.ctrtype = ctrclass; ctrmodel.ctrvalue = ctrtext; refctrlist.Add(ctrmodel); } else if (ctrclass.ToUpper().Contains("WINDOW")) { List<IntPtr> childCtrHandleList = mw.GetChildControlsHandle(ctrHandle); foreach (IntPtr childCtrHandle in childCtrHandleList) { GetControlsText(childCtrHandle, ref refctrlist); } } else if (ctrclass.ToUpper().Contains("SYSLISTVIEW32")) { GetListViewControlText(ctrHandle, ref refctrlist); } else { ctrmodel.ctrhandleid = ctrHandle.ToInt32(); ctrmodel.ctrtype = ctrclass; refctrlist.Add(ctrmodel); } #endregion } private void GetListViewControlText(IntPtr ctrHandle, ref List<ControlModel> refctrlist) { int lvrowscount = 0; int lvcolscount = 0; ControlModel ctrmodel = new ControlModel(); ListViewControl lvcontrol = new ListViewControl(); lvrowscount = lvcontrol.ListView_GetItemRows(ctrHandle); lvcolscount = lvcontrol.ListView_GetItemCols(ctrHandle); string reftext = ""; //打开并插入进程 if (lvrowscount > 0 && lvcolscount > 0) { string[,] strls = lvcontrol.GetListViewItmeValue(processid,ctrHandle, lvrowscount, lvcolscount); for (int i = 0; i < lvrowscount; i ) { for (int j = 0; j < lvcolscount; j ) { reftext = strls[i, j] "|"; } } } ctrmodel.ctrhandleid = ctrHandle.ToInt32(); ctrmodel.ctrtype = "SysListView32"; ctrmodel.ctrvalue = reftext; refctrlist.Add(ctrmodel); } } }