Note that there are some explanatory texts on larger screens.

plurals
  1. POuser32.dll FindWindowEx, finding elements by classname on remote WPF window
    primarykey
    data
    text
    <p>I have a WPF application that is being started from a command-line application. </p> <p>I am trying to do some simple automation (get/set text, click some buttons, etc). I cannot seem to find any of the child windows in WPF. </p> <p>I have working models with WPF and UIA Framework, WinForms and WinAPI, but cannot seem to get WinAPI and WPF to play nicely.</p> <p>I have used UISpy, WinSpy++, Winspector, the UIA Verify app to look at the controls, etc, but they do not seem to carry the same information for WPF as WinForms.</p> <p>For example, in the WinForms app, I see a textbox with a ClassName of "WindowsForms10.EDIT.app.0.33c0d9d" when I look via the spy tools. The UIA Automation Verify app is the only one to acknowledge the element exists and reports "TextBox".</p> <p>So, my question is how do I find the correct class name to pass or is there an easier route to find the child elements?</p> <pre><code>// 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); </code></pre> <p>and here is the user32.dll imports I am using:</p> <pre><code>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); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload