如何将任何应用程序的选定文本放入 windows 窗体应用程序 [英] How to get selected text of any application into a windows form application
问题描述
这就是我想要做的,
当用户通过双击鼠标选择任何正在运行的应用程序的任何单词(文本)时,应将特定突出显示的单词插入到已经运行的 Windows 应用程序中.
When user select any word(text) of any running application by double clicking the mouse particular highlighted word should be inserted into a windows application which is already running.
到目前为止,我已经使用 Global Keystroke
实现了逻辑,其中用户必须触发 CRT+ C 键盘组合键来复制选定的单词进入 win 表单应用程序.
So far I have implemented the logic using Global Keystroke
where user has to trigger CRT+ C keyboard key combination to copy the selected word into win form application.
我想知道有没有什么方法可以让那些选定的文本进入应用程序而无需按键盘上的任何按钮?
What i want to know is there any way to get those selected text into the application without having any button key press of the keyboard?
推荐答案
经过一番阅读,我找到了方法:
After some reading, I have found the way:
- 使用类似globalmousekeyhook.codeplex.com
- (可选)保存剪贴板的当前状态
- 使用
user32.dll
中的 使用
WindowFromPoint
根据光标位置获取窗口来自user32.dll
GetCursorPos
获取当前鼠标位置- Hook the double click event using something like globalmousekeyhook.codeplex.com
- (Optional) Save the current state of the clipboard
- Get The current mouse position with
GetCursorPos
fromuser32.dll
Get windows based on cursor position with
WindowFromPoint
fromuser32.dll
[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(Point lpPoint);
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out Point lpPoint);
public static IntPtr GetWindowUnderCursor()
{
Point ptCursor = new Point();
if (!(PInvoke.GetCursorPos(out ptCursor)))
return IntPtr.Zero;
return WindowFromPoint(ptCursor);
}
使用 SendMessage
形式发送复制命令 user32.dll
(请参阅使用 User32.dll SendMessage 发送带有 ALT 修饰符的键)
Send copy command with SendMessage
form user32.dll
(see
Using User32.dll SendMessage To Send Keys With ALT Modifier)
这篇关于如何将任何应用程序的选定文本放入 windows 窗体应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!