获取活动窗口中的选定项目
我正在使用 C# 开发一个与剪贴板一起使用的应用程序,我想知道是否可以获取用户在当前窗口中选择的内容,无论它是什么窗口(例如可能是 FireFox、记事本等) .)。
I am using C# to develop an application that works with the clipboard, an was wondering if its possible to get the contents of what the user has selected in the current window, no matter what window it is (e.g. could be FireFox, notepad, etc.).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您是否能够找到解决此问题的通用解决方案。看看这个链接;
http://www.eggheadcafe .com/software/aspnet/33899121/get-selected-text-of-active-window-.aspx
这篇文章的作者报告说,他们的解决方案适用于记事本,但不适用于写字板或 Word。我对这个领域了解不多,但我猜这意味着有多种方法可以实现文本选择 - 即使在 Windows 中也是如此。
我认为这也适用于 Control-C,而不仅仅是文本选择。我相信根据使用复制命令的上下文,有不同的处理复制命令的方法。
例如,如果您在 Windows 中的对话框上按 Control-C,它将复制文本,而无需您手动选择它。
希望上面的链接对您有用。这似乎是一个需要克服的有趣问题。
编辑:
说得太早 - 刚刚找到此链接;
http://social.msdn.microsoft.com/Forums/en/winformsapplications/thread/1dc356e6-9441-44de-9eda-247003fa6ef5
看起来这正是您所追求的 - 希望有效。
I'm not sure if you're going to be able to get a general solution for this problem. Take a look at this link;
http://www.eggheadcafe.com/software/aspnet/33899121/get-selected-text-of-active-window-.aspx
The author of this post reports that their solution works in Notepad, but not in Wordpad or Word. I don't know much about this area, but I would guess that this means there are various means through which text selection is implemented - even within Windows.
I think this also extends to Control-C, not just text selection. I believe that there are different ways of handling the copy command depending on the context in which it's used.
For example, if you press Control-C on a dialog box in Windows, it will copy the text without you have to select it manually.
Hopefully the link above is of some use to you. This seems like an interesting problem to overcome.
Edit:
Spoke too soon - just found this link;
http://social.msdn.microsoft.com/Forums/en/winformsapplications/thread/1dc356e6-9441-44de-9eda-247003fa6ef5
Looks like this is exactly what you're after - hope that works.
如果仅选择某些内容,则它不会出现在剪贴板中。但是,如果用户复制了他之前选择的某个对象,那么,是的,它将位于剪贴板中。
If something was only selected, it won't appear in the Clipboard. But if user copied some object that he had previously selected, then, yes, it will be in the Clipboard.