2016-09-16 8 views
-1

私はそれを読むことができるアプリケーションをいくつか持っています、それは可能ですか? (それは私のアプリではないので、私はそれのソースコードを持っていない)。 例えば、私はWindows caluculator appのテキストボックスのデータを読んでいると仮定します。C# - いくつかのアプリケーションのデータグリッドビューを読む

これらの問題を扱う 'Autoit'ソフトウェアについては、プログラムでC#で可能ですか?

+0

私はそうは考えていません。 –

+0

アクセスしようとしているプログラムにアクセスするためのインターフェースがない場合は、情報を取得する方法がありません。 – Markai

+0

これはC#で利用できないかもしれませんが、私は 'autoit'で試してみます – tomerJK

答えて

0

のAutoItはLIBSはここで見つけることができ、C#ので利用可能である:例えば

https://www.autoitscript.com/site/autoit/downloads/

をあなたがこれを行うことができカルクアプリの値を取得するには:

AutoItX.WinWait("[CLASS:CalcFrame]", "", 10); 
var win = AutoItX.WinGetHandle("[CLASS:CalcFrame]"); 
string strReturnText = AutoItX.WinGetText(win).Trim(); 

あなたドン場合あなたはPInvokeを使うことができます。

あなたはこのようなのPInvokeとカルクウィンドウのハンドルを取得することができます。

[DllImport("USER32.DLL", CharSet = CharSet.Unicode)] 
public static extern IntPtr FindWindow(string lpClassName, 
string lpWindowName); 

IntPtr handle = FindWindow("CalcFrame", "Calculator"); 

などを...

より複雑な例を参照するには、インターネット内のタブを取得するためにここに私の答えを読むことができます冒険者。 PInvokeの程度

https://stackoverflow.com/a/37595421/5703316

さらに詳しい情報:

http://pinvoke.net/

EDIT

私はあなたのための最良の方法は、私がやったSystem.Windows.Automation;

を使用することだと思ういくつかの思考の後yを示す少しの例オートメーションフレームワークの使い方

それはこの小さなWindowsFormのアプリのグリッドヘッダを取得するコンソールアプリケーションです:

enter image description here

とコード:

static void Main(string[] args) 
    { 
     int id = System.Diagnostics.Process.GetProcessesByName("WindowsFormsApplication1")[0].Id; 
     AutomationElement desktop = AutomationElement.RootElement; 
     AutomationElement bw = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ProcessIdProperty, id)); 

     AutomationElement datagrid = bw.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "dataGridView1")); 

     AutomationElementCollection headers = datagrid.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Header)); 

     var headerCol1 = headers[1].Current.Name; ; 
     var headerCol2 = headers[2].Current.Name; 

     Console.WriteLine(headerCol1 + " " + headerCol2); 

    } 

あなたはSO操作する上で多くのQ/Aを見つけることができますUIオートメーションを使用したDataGridView:

Getting full contents of a Datagrid using UIAutomation

UI Automation not working for DataGridView

+1

これはちょうどAutoItの使い方を示していますが、質問には答えません。 –

+0

電卓を読むのはかなり簡単です...私はdatagridviewを読み取ることができません – tomerJK

+0

私は知っている、私は最良の方法は、UIのオートメーションフレームワークを使用すると思う、私は私の答えを編集します。 –

関連する問題