3

特定のプロセスのウィンドウ クラス名を取得するにはどうすればよいですか? これをC#で実現したい。

c# でプロセス クラスを試しましたが、プロセスのウィンドウ名しか取得できません。

ありがとう

4

2 に答える 2

7

プロセスのメインウィンドウのクラス名を取得したいということだと思います。

これを行うにMainWindowHandleは、Processオブジェクトの を使用してメイン ウィンドウへのハンドルを取得し、次の相互運用メソッドを使用してクラス名を取得する必要があります。

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);

サンプル コードについてはpinvoke.netを、関数の詳細についてはMSDNを参照してください。

于 2012-09-11T14:56:35.187 に答える
1

また、 windows ui 自動化フレームワークを使用して、pinvoke を使用せずにこれを実現することもできます。

        int pidToSearch = 316;
        //Init a condition indicating that you want to search by process id.
        var condition = new PropertyCondition(AutomationElementIdentifiers.ProcessIdProperty, 
            pidToSearch);
        //Find the automation element matching the criteria
        AutomationElement element = AutomationElement.RootElement.FindFirst(
            TreeScope.Children, condition);

        //get the classname
        var className = element.Current.ClassName;
于 2012-09-11T15:07:19.190 に答える