- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在编写一个自动程序(C#,而不是 C++),我需要在表单中获取 RichTextBox。我用Spy++
获取标题和类名,但是FindWindowEx
总是找不到RichTextBox
,GetLastError
获取单词 0
。这是一个简单的例子。
IntPtr parent = FindWindow(null, "Form1");
if (parent!=IntPtr.Zero) {
//find test1 textbox
IntPtr child = FindWindowEx(parent, 0,null, "test1");
if (child!=IntPtr.Zero) {
SendMessage(child, 0x000c, 0, lParam: "test");
} else {
Console.WriteLine("textbox can't be found");
}
//find test2 richtextbox
IntPtr childRich = FindWindowEx(parent, 0, null, "test2");
if (childRich != IntPtr.Zero) {
SendMessage(child, 0x000c, 0, lParam: "test");
} else {
Console.WriteLine("richtextbox can't be found");
}
} else {
Console.WriteLine("Form1 can't be found");
}
但结果是richtextbox 找不到
。帮助我。
最佳答案
我真的不认为这是最好的方法,但它是某种东西。
对于这种特定情况,您可以搜索表单中的所有处理程序,然后更改所需的处理程序。
var iHandle = Win32.FindWindow(null, "Form1");
var allItems = Win32.GetAllChildrenWindowHandles((IntPtr)iHandle, int.MaxValue);
Win32.SendMessage(allItems[1], 0x000c, 0, lParam: "Now you can change the text!");
我已经测试过,allItems[1] 将始终是相同的项目,我认为这是项目在 winForm 中从上到下排序的方式。
我正在为 Win 方法使用第二个类:
public class Win32
{
public const int WM_SETTEXT = 0X000C;
public static List<IntPtr> GetAllChildrenWindowHandles(IntPtr hParent, int maxCount)
{
var result = new List<IntPtr>();
int ct = 0;
IntPtr prevChild = IntPtr.Zero;
IntPtr currChild = IntPtr.Zero;
while (true && ct < maxCount)
{
currChild = FindWindowEx(hParent, prevChild, null, null);
if (currChild == IntPtr.Zero) break;
result.Add(currChild);
prevChild = currChild;
++ct;
}
return result;
}
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll")]
public static extern int FindWindow(string strClassName, string strWindowName);
}
编辑:获取所有子窗口句柄的方法:https://jamesmccaffrey.wordpress.com/2013/02/03/getting-all-child-window-handles-using-c-pinvoke-findwindowex/
关于c# - 为什么 "FindWindowEx"找不到RichTextBox组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50638850/
我正在尝试获取子对话窗口的句柄。我试过使用 FindWindowEx,但没有用。相反,FindWindow 确实起作用了。 我用 visual studio 的选项窗口做了一个实验,代码如下: Int
我正在尝试获取子对话窗口的句柄。我试过使用 FindWindowEx,但没有用。相反,FindWindow 确实起作用了。 我用 visual studio 的选项窗口做了一个实验,代码如下: Int
我试图在对话框打开后立即找到它的句柄。 现在,一旦对话框打开,我就尝试在单独的线程中为该对话框调用 FindWindowEx,但它返回 NULL。 然后我在调用 FindWindowEx 之前睡了一会
我正在使用 C 进行编程,并且我正在以编程方式远程单击按钮。我已经在简单的、各种简单形式的应用程序中完成了它。但是我遇到了一个问题。 HWND WINAPI FindWindowEx(HWND hwn
您好,为 outlook 2007 创建了插件。现在插件还需要支持 outlook 2010。但是以下代码在检查获取 outlook 窗口句柄时失败。 hWnd = ::FindWindowEx(*p
我应该编写一个自动安装程序。只是您启动的一个程序,它应该自行完成安装向导,无需用户进行任何操作。 我目前正在开发的程序叫做 Cygwin。而我想要做的就是一遍又一遍地点击“下一步”按钮,直到安装完成。
我想打开 Microsoft Security Essential 程序,然后用 VC 单击“立即扫描”按钮。我可以找到窗口但找不到控件。这是我的代码,当我运行此代码时它显示 Control not
我正在编写一个自动程序(C#,而不是 C++),我需要在表单中获取 RichTextBox。我用Spy++获取标题和类名,但是FindWindowEx总是找不到RichTextBox,GetLastE
我可以选择使用 API EnumChildWindows 或 FindWindowEx 中的任何一个。 有什么建议哪个 api 性能更好? FindWindowEx 是否在内部使用 EnumChild
我在做什么? 我正在自动化第 3 方应用程序。登录窗口看起来像这样 注意:表单中嵌入了背景图像,USERNAME 和 PASSWORD 实际上都是图像的一部分。以防万一有人想知道为什么 Window
我正在开发一个小程序,以便在使用 Microsoft 远程协助 (msra.exe) 时让我的生活更轻松。使用 C++,我可以打开 msra.exe,然后找到窗口句柄。然后我想找到子窗口(按钮),并与
我正在构建一个应用程序,它将获得所有对应用程序 winform 运行的控制。首先,我可以将 dll 注入(inject)正在运行的应用程序 winform 并获取正在运行的应用程序 winform
根据 http://msdn.microsoft.com/en-us/library/ms633500(v=vs.85).aspx我定义了 FindWindowEx 函数。 using System.
我有一个可视化基本应用程序,它需要找到具有消息框的 Microsoft Access,然后将 Enter 发送到消息框。 我关注了这篇文章( FindWindow FindWindowEx )。 它找
我注意到,如果您针对属于不在前台(即最小化)窗口的 hWnd 调用 FindWindowEx 或 EnumChildWindows,则它们不会报告任何 children 。另一方面,如果我首先对正在查
如下创建一个 IP 地址窗口,然后尝试使用 FindWindowEx 函数找到它: INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(IN
我继承了一个我并不真正喜欢的 C# 窗口应用程序。我的最后期限迫在眉睫,我害怕得要命,因为我的某些更改可能会对现有功能产生不利影响。 我有 RoR 的爱好者背景,我对在该框架中进行测试(同时使用 RS
我有一个简单的程序,它在传递给 EnumChildWindows 的回调中使用 FindWindowEx & strncmp() 来查找由第三方应用程序创建的对话框,然后按下按钮。 此代码在我的 Wi
我需要以编程方式处理另一个 Windows 应用程序,搜索谷歌我找到了一个示例,它使用 DLLImport 属性处理 Windows 计算器并将 user32.dll 函数导入 C# 中的托管函数。
我是一名优秀的程序员,十分优秀!