gpt4 book ai didi

c# - 如何使用 C# 在 Powerpoint 2013 中获取鼠标光标下的单词?

转载 作者:太空狗 更新时间:2023-10-29 19:40:50 26 4
gpt4 key购买 nike

我想知道 Powerpoint 中鼠标光标下的单词,以便它可以用于屏幕阅读器。如果可访问性解决方案可以区分不同的词(相对于 block ),则它是可以接受的。

最佳答案

这真的很难,如果你不知道自己在做什么。有一个简单的方法和一个困难的方法来做到这一点。简单的方法是使用 Microsoft UI 自动化框架(包括 Powerpoint 自动化)。也可以使用替代框架。

困难的方法是直接使用 win api。

例如:获取当前鼠标下的窗口标题。

    public static class dllRef
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetCursorPos(out Point lpPoint);
[DllImport("user32.dll")]
private static extern IntPtr WindowFromPoint(Point point);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int RegisterWindowMessage(string lpString);
[DllImport("user32.dll", EntryPoint = "SendMessage", CharSet = CharSet.Auto)]
public static extern bool SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SendMessage(int hWnd, int Msg, int wparam, int lparam);

public const int WM_USER = 0x400;
public const int WM_COPYDATA = 0x4A;
public const int WM_GETTEXT = 0x000D;
public const int WM_GETTEXTLENGTH = 0x000E;

public static void RegisterControlforMessages()
{
RegisterWindowMessage("WM_GETTEXT");
}

public static string GetText()
{
StringBuilder title = new StringBuilder();
Point p = dllRef.getMousePosition();
var lhwnd = dllRef.WindowFromPoint(p);
var lTextlen = dllRef.SendMessage((int)lhwnd, dllRef.WM_GETTEXTLENGTH, 0, 0).ToInt32();
if (lTextlen > 0)
{
title = new StringBuilder(lTextlen + 1);
SendMessage(lhwnd, WM_GETTEXT, title.Capacity, title);
}
return title.ToString();
}

public static Point getMousePosition()
{
Point p = new Point();
GetCursorPos(out p);
return p;
}
}

    private void Form1_Load(object sender, EventArgs e)
{
Timer t = new Timer();
t.Interval = 25;
t.Tick += new EventHandler(Timer_Tick);
t.Start();
}
public void Timer_Tick(object sender, EventArgs eArgs)
{
this.label1.Text = dllRef.GetText();
}

此外,您还可以使用 Microsoft Spy++

enter image description here

查找您要查找的信息是否已公开。除此之外,我真的可以推荐你使用建立在这个之上的层的自动化框架。 Google 在这方面有足够多的示例(以及如何构建复杂的键盘记录器)。

关于c# - 如何使用 C# 在 Powerpoint 2013 中获取鼠标光标下的单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32402181/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com