コマンドライン アプリケーションから開始される WPF アプリケーションがあります。
簡単な自動化(テキストの取得/設定、ボタンのクリックなど)を試みています。WPF で子ウィンドウが見つからないようです。
私は WPF と UIA フレームワーク、WinForms と WinAPI を使用した作業モデルを持っていますが、WinAPI と WPF をうまく動作させることができないようです。
UISpy、WinSpy++、Winspector、UIA Verify アプリを使用してコントロールなどを確認しましたが、WPF について WinForms と同じ情報を持っていないようです。
たとえば、WinForms アプリで、スパイ ツールを調べると、「WindowsForms10.EDIT.app.0.33c0d9d」という ClassName のテキスト ボックスが表示されます。UIA Automation Verify アプリは、要素の存在を認識し、"TextBox" を報告する唯一のアプリです。
それで、私の質問は、渡す正しいクラス名をどのように見つけるか、または子要素を見つけるためのより簡単なルートはありますか?
// does not work in wpf
IntPtr child = NativeMethods.FindWindowEx(parent, prevElement, "TextBox", null);
// works in winforms
IntPtr child = NativeMethods.FindWindowEx(parent, prevElement, "WindowsForms10.EDIT.app.0.33c0d9d", null);
そして、これが私が使用しているuser32.dllインポートです:
public class NativeMethods
{
public const int WM_SETTEXT = 0x000C;
public const int WM_GETTEXT = 0x000D;
public const uint CB_SHOWDROPDOWN = 0x014F;
public const uint CB_SETCURSEL = 0x014E;
public const int BN_CLICKED = 245;
public const uint WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr GetDlgItem(IntPtr hDlg, int nIDDlgItem);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
public static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, string lParam);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
public static extern int SendMessage(int hWnd, int Msg, int wParam, StringBuilder lParam);
}