0

私はstackoverflowにリストされているこれを実行しようとするいくつかの例を調べましたが、.NETコーディングのためにこれを実行する方法をリストするものは何も見つかりませんでした。また、ポップアップを検出するために必要です。ポップアップが見つかったら、ウィンドウのタイトルとポップアップ内のテキストをプルします。

私は投稿を使ってみました: how-can-i-change-text-on-a-win32-window

しかし、ポップアップが存在するかどうかを確認する方法だけを「テキストを取得」する方法を見つけようとしてもうまくいきませんでした。テキストを取得しようとしているウィンドウは、標準のWindowsエラーウィンドウ(#32770)、別名WIN32クリティカルポップアップウィンドウ(赤のXが付いたウィンドウ)です。エラーウィンドウのタイトルは常に「TLP2011」になると思います

タイトル、テキストを読み取って、エラーボタンの[OK]をクリックするだけです。

理由?ITを実行しているソフトウェアがあり、着信コストを削減するために、ポップアップ時にエラーを検出するプログラムを作成し、エラーが検出されたらエラーウィンドウを閉じて、エラーが自動的に修正されることをユーザーに通知します。(私の新しいプログラムは、このエラーが再び表示されないようにエラーを自動的に修正する方法を決定するために、エラーウィンドウからテキストを読み取ることができる必要があります)

----------最新の検索結果を表示するように編集------------

次のリンクを投稿してくれたGXに感謝します。C#アプリでSpy ++と同様の機能を取得するにはどうすればよいですか?

今、私は次のようなものが必要であると判断しました:

Dim pProcess() As Process = Process.GetProcessesByName("TLP2011")

    For Each p As Process In pProcess
        For Each threadInfo As ProcessThread In p.Threads

            ' uncomment to dump thread handles
            'Console.WriteLine("\tthread {0:x}", threadInfo.Id);
            Dim windows As IntPtr() = GetWindowHandlesForThread(threadInfo.Id)
            If windows IsNot Nothing AndAlso windows.Length > 0 Then
                For Each hWnd As IntPtr In windows
                    Console.WriteLine(vbTab & "window {0:x} text:{1} caption:{2}", hWnd.ToInt32(), GetText(hWnd), GetEditText(hWnd))
                Next
            End If
        Next
    Next

これで、実際のプログラム自体のすべてが一覧表示されます。すべてのテキストとすべて。ポップアップボックスを選び出すコツを知っている人はいますか?

これが表示されるものの例です

window 3d21aa text:Select Package caption:
window 551176 text: caption:
window e8147c text:Do Not Auto Show  caption:Do Not Auto Show 
window 8e21c6 text:&Select All caption:&Select All
window 2300e10 text:&Help caption:&Help
window 762164 text:Cancel caption:Cancel
window 330f0e text:OK caption:OK
window e8147c text:Do Not Auto Show  caption:Do Not Auto Show 
window 8e21c6 text:&Select All caption:&Select All
window 2300e10 text:&Help caption:&Help
window 762164 text:Cancel caption:Cancel
window 330f0e text:OK caption:OK
window 10f20a6 text: caption:
window 5f122ce text: caption:
window 1824e2 text: caption:
window 1824e2 text: caption:
window 5f122ce text: caption:
window 1824e2 text: caption:
window 1824e2 text: caption:
window 6e1be4 text: caption:
window 342162 text: caption:
window 1c1b92 text: caption:
window 65105a text: caption:Admin
window 291f72 text: caption:
window 375104e text: caption:
window 375104e text: caption:
window 1c1b92 text: caption:
window 65105a text: caption:Admin
window 291f72 text: caption:
window 375104e text: caption:
window 375104e text: caption:
window 242308 text:Form Filter caption:
window 9ee294e text: caption:
window 8ff0f54 text: caption:All Status
window 468273c text: caption:
window 1d110c text: caption:
window 1d110c text: caption:
window 8ff0f54 text: caption:All Status
window 468273c text: caption:
window 1d110c text: caption:
window 1d110c text: caption:
window b90bea text:cbEngine caption:
window 5b17b0 text: caption:
window ee24c6 text: caption:
window ee24c6 text: caption:
window fc1ae0 text: caption:
window 141cfc text:TLP2011 caption:
window d51928 text:OK caption:OK
window 2c1223c text: caption:
window 100f08 text:Access violation at address 6CABC667 in module 'tlpcore.dll'. Write of address F8FFFF86. caption:Access violation at address 6CABC667 in module 'tlpcore.dll'. Write of address F8FFFF86.
window b2a214e text: caption:

エラーボックスを見つけるためのより良い方法を知っている人はいますか?「TLP2011」を検索してから、次の3行を使用して、msgboxテキストが非常に「信頼できる」方法であると判断することはないと思います。誰かがそれをもっと選び出す方法を知っていますか?

----より多くの考えを追加しました----

10秒ごとにすべての異なるスレッドでこれをチェックすると、システムに大きな負荷がかかるように見えます。これは本当にこれを行うための最も論理的な方法ですか?

4

1 に答える 1

0

ガエターノは彼の応答でそれを正しくしました

static void Main(string[] args)
{
    foreach (Process procesInfo in Process.GetProcesses())
    {
        Console.WriteLine("process {0} {1:x}", procesInfo.ProcessName, procesInfo.Id);
        foreach (ProcessThread threadInfo in procesInfo.Threads)
        {
            // uncomment to dump thread handles
            //Console.WriteLine("\tthread {0:x}", threadInfo.Id);
            IntPtr[] windows = GetWindowHandlesForThread(threadInfo.Id);
            if (windows != null && windows.Length > 0)
                foreach (IntPtr hWnd in windows)
                    Console.WriteLine("\twindow {0:x} text:{1} caption:{2}",
                        hWnd.ToInt32(), GetText(hWnd), GetEditText(hWnd));
        }
    }
    Console.ReadLine();
}

private static IntPtr[] GetWindowHandlesForThread(int threadHandle)
{
    _results.Clear();
    EnumWindows(WindowEnum, threadHandle);
    return _results.ToArray();
}

// enum windows

private delegate int EnumWindowsProc(IntPtr hwnd, int lParam);

[DllImport("user32.Dll")]
private static extern int EnumWindows(EnumWindowsProc x, int y);
[DllImport("user32")]
private static extern bool EnumChildWindows(IntPtr window, EnumWindowsProc callback, int lParam);
[DllImport("user32.dll")]
public static extern int GetWindowThreadProcessId(IntPtr handle, out int processId);

private static List<IntPtr> _results = new List<IntPtr>();

private static int WindowEnum(IntPtr hWnd, int lParam)
{
    int processID = 0;
    int threadID = GetWindowThreadProcessId(hWnd, out processID);
    if (threadID == lParam)
    {
        _results.Add(hWnd);
        EnumChildWindows(hWnd, WindowEnum, threadID);
    }
    return 1;
}

// get window text

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

private static string GetText(IntPtr hWnd)
{
    int length = GetWindowTextLength(hWnd);
    StringBuilder sb = new StringBuilder(length + 1);
    GetWindowText(hWnd, sb, sb.Capacity);
    return sb.ToString();
}

// get richedit text 

public const int GWL_ID = -12;
public const int WM_GETTEXT = 0x000D;

[DllImport("User32.dll")]
public static extern int GetWindowLong(IntPtr hWnd, int index);
[DllImport("User32.dll")]
public static extern IntPtr SendDlgItemMessage(IntPtr hWnd, int IDDlgItem, int uMsg, int nMaxCount, StringBuilder lpString);
[DllImport("User32.dll")]
public static extern IntPtr GetParent(IntPtr hWnd);

private static StringBuilder GetEditText(IntPtr hWnd)
{
    Int32 dwID = GetWindowLong(hWnd, GWL_ID);
    IntPtr hWndParent = GetParent(hWnd);
    StringBuilder title = new StringBuilder(128);
    SendDlgItemMessage(hWndParent, dwID, WM_GETTEXT, 128, title);
    return title;
}
于 2014-12-12T04:44:24.083 に答える