想获取另外一个程序中的TDrawGrid表格中的数据,应该怎么实现?
解决方案 »
- 高手来做做中软国际面试题
- 打印对话框中如何显示总页数
- 有谁知道windows install的安装路径属性
- 多线程跟Socket问题?(工业基础薄弱,没走两步又碰到麻烦了)
- C#如何实现这种功能:不用人手动去按键,而自动通过一个函数调用,来实现相当于人手按了一下"alt"键的功能???大侠们指教!
- 做一个小的CAD系统,滚动条应该怎么使用呢?
- 键入小写字母,显示大写字母(有分就用)
- WPF CheckBox 决定 ListView 的输出 问题
- C#程序如何与USB接口通信
- 如何用C#编程使之在Windows98下运行得到硬盘盘序列号
- 求一个水晶报表
- 程序运行时,配置文件xxxx.exe.config更改了有没有事件触发?
首先你应该知道你需要获取的数据,来自于另外的一个程序,或者叫另外一个进程,
这就涉及到一个进程间通讯的问题,Remoting可以实现跨进程或计算机边界进行通讯。或者用简单的SOCKET也能够实现,关于这方面的资料网上有很多参考的。
<html>
<head><title>LoadTable</title></head>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script><script type="text/javascript">
$(function()
{
$("#test").click(function(){$("#show").load("table.html table[id*=TDrawGrid]");}); });
</script>
<body>
<input type="button" id="test" value="LoadTable"/>
<div id="show"></div></body>
</html>table.html
<table id="TDrawGrid" border="1">
<thead style="background-Color:#DFD"><th>Titel1</th><th>Titel2</th><th>Titel3</th><th>Titel4</th>
</thead>
<tbody>
<tr><td>test1</td><td>test2</td><td>test3</td><td>test4</td></tr>
<tr><td>test1</td><td>test2</td><td>test3</td><td>test4</td></tr>
<tr><td>test1</td><td>test2</td><td>test3</td><td>test4</td></tr>
<tr><td>test1</td><td>test2</td><td>test3</td><td>test4</td></tr>
<tr><td>test1</td><td>test2</td><td>test3</td><td>test4</td></tr>
</tbody>
</table>
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Reflection;
using System.Threading;namespace GetTDrawGrid
{
static class Program
{
static Form m_TargetForm = null;
static BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
static int delay = 1000;
[STAThread]
static void Main()
{
try
{
Console.WriteLine("\nLaunching target app");
string exePath = @"..\\..\\..\WinApp\bin\Debug\TDrawGrid.exe"; //the file contains TDrawGrid m_TargetForm = LaunchApp(exePath, "TDrawGrid.Form1"); //Form1 is the container of TDrawGrid control
//根据TDrawGrid的数据结构修改此句的数据返回类型和属性名(这里是Rows)控件名是tDrawGrid1
DataGridViewRowCollection c1 = (DataGridViewRowCollection)GetControlPropertyValue("tDrawGrid1", "Rows");
// Process the return value
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
Console.ReadLine();
}
}
static object GetControlPropertyValue( string controlName, string propertyName)
{
if (m_TargetForm.InvokeRequired)
{
Thread.Sleep(delay);
return m_TargetForm.Invoke(new GetControlPropertyValueHandler(GetControlPropertyValue), new object[] { controlName, propertyName });
}
Type t1 = m_TargetForm.GetType();
FieldInfo fi = t1.GetField(controlName, flags);
object ctrl = fi.GetValue(m_TargetForm);
Type t2 = ctrl.GetType();
PropertyInfo pi = t2.GetProperty(propertyName, flags);
return pi.GetValue(ctrl, new object[0]);
}
delegate object GetControlPropertyValueHandler(string controlName, string propertyName); static Form LaunchApp(string exePath, string formName)
{
Thread.Sleep(delay);
Assembly a = Assembly.LoadFrom(exePath);
Type formType = a.GetType(formName);
Form resultForm = (Form)a.CreateInstance(formType.FullName);
Thread t = new Thread(new ThreadStart(new AppState(resultForm).RunApp));
t.ApartmentState = ApartmentState.STA;
t.IsBackground = true;
t.Start();
return resultForm;
} private class AppState
{
public AppState(Form f) { FormToRun = f; }
public readonly Form FormToRun;
public void RunApp()
{
Application.Run(FormToRun);
}
}
}
}
因为程序我没有源代码,程序应该是用delphi写的,TDrawGrid控件名称也无法获取到,但是可以得到句柄,是否可以对这个控件的内容进行操作呢?我试过如果是TextBox的话,可以通过SendMessage或PostMessage方法修改控件内容或是获取控件内容信息,但是TDrawGrid不知道怎么下手.
如果是用C#的话,就要引入许多的WindowsAPI。
基本思路好像是:
找到别人的应用程序,列举当前窗口所有的控件,
直到找到你要的GridView。
列举GridView里列和行,发送消息过去,获得数据。具体的我记不清了。以前的一个Demo,仅供参考下载完的压缩包里,先运行Exec.exe,再运行EnumControls.exe,
单击【列举窗体中的控件】,在点击复制SG中的数据,
就可以把Exec.exe里的数据拷贝到EnumControls.exe中了。
HookSG.dll 这个文件的代码。
我回头找找,给发上来。
不过调用这个动态库,应该可以读取到你要的数据。
我可以通过外部工具得到Grid控件的句柄,应该可以直接获取到控件的,现在主要是有三个问题:
1、用: DataGridViewRowCollection 是否可以把TDrawGrid转过来?
2、如果可以,怎么可获取到他的行和列呢?
3、怎么查读到值?
你用我的那个测试Demo可以读取到数据的。
我就找找动态库的资料发给你,或者你自己也可以找找看。
从StringGrid里读取数据的这个例子,我是从网上查资料的来的。
StringGrid和TDrawGrid是同一个控件吗?
当然,我没有亲自试过。
你那个demo是delphi的吗?有没有c#的啊?
http://topic.csdn.net/u/20100104/09/d0f7a2a1-8dcb-4bef-9e0f-aff6732847d5.html 1000分求购C#读取TDrawGrid表格数据源代码
http://topic.csdn.net/u/20100106/09/235527a4-1ea0-4b43-8637-ca9dd528865c.html
有办法解决的哥们,请看上面的两个链接,谢谢