user32.dll。我如何找到文本框?

user32.dll. How do i find textbox?

到目前为止,我使 window - 活动,使用 SendKeys 发送文本,但我想在后台使用 SendMessage

IntPtr main = FindWindow(null, "Label Code (Scan)");
if (!main.Equals(IntPtr.Zero))
    {
      if (SetForegroundWindow(main))
         {
            SendKeys.SendWait(code);
            SendKeys.SendWait("{ENTER}");
          }
     }  

我试过类似的东西:

IntPtr main = FindWindow(null, "Label Code (Scan)");
SendMessage(main, 0x000C, 0, "Hello");

但它将 window 的标题重命名为 "Hello"。看起来,我需要找到 child window,但找不到 lpszClass

public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

window 中的控件不是真正的 Windows 控件。它们由 Window 本身绘制和管理。但是,window 可能支持 Windows 自动化框架以允许与控件进行交互。

使用工具Inspect检查window是否支持Windows自动化API。

如果是,请使用 classes in System.Windows.Automation 和您在检查工具中看到的信息来设置文本。