【问题标题】:Get around disabled selection绕过禁用的选择
【发布时间】:2011-10-29 13:32:25
【问题描述】:

我有一个显示信息的程序(简单的文本,但不在 txt 框中,看起来像 .NET 中的标签)但禁用了选择并禁用了左右鼠标单击。

我想编写另一个程序(可以说是 C#,但也可以是其他语言)充当用户并将第一个程序显示的信息写在 txt 文件中。

有没有办法绕过禁用的选择,鼠标左键和右键?

【问题讨论】:

    标签: c#


    【解决方案1】:

    GetWindowText windows API 是你的朋友:

    [DllImport("user32.dll", EntryPoint = "GetWindowText", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
    private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount);
    

    您必须获取其他程序窗口的句柄,然后使用EnumChildWindows 在所有子窗口/控件上循环,然后针对所有这些句柄获取调用GetWindowText 的文本。在某些情况下,我猜你不会得到预期的结果,或者可能是某些控件没有暴露句柄。

    [DllImport("user32")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i);
    

    有关如何使用EnumChildWindows 的详细信息和答案,请参见此处:

    Why is EnumChildWindows skipping children?

    也可以在这里查看一些想法和示例...Why does GetWindowText hang with a "closed" handle but not with a random one

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-17
      相关资源
      最近更新 更多