你如何在 C++ 中从剪贴板复制/粘贴?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6436257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you copy/paste from the clipboard in C++?
提问by Felice Pollano
I'm still a C++ newbie who has only recently learned some file manipulation. I looked it up online and the codes given are way beyond my current skill. Is there a simple way to do this, or are there any good tutorials that can explain this from the very basics?
我仍然是一个 C++ 新手,最近才学会了一些文件操作。我在网上查了一下,给出的代码远远超出了我目前的技能。有没有一种简单的方法可以做到这一点,或者是否有任何很好的教程可以从基础知识解释这一点?
回答by Felice Pollano
In windowslook at the following API:
在Windows 中查看以下 API:
An extensive discussion can be found here. Obviously this topic is strongly operating system related. And if you are using some framework (ie MFC/ATL) you generally find some helper infrastructure. This reply refer to the lowest API level in WIndows. If you are planning to use MFC have a look here, if you prefer ATL look here.
可以在此处找到广泛的讨论。显然,这个话题与操作系统密切相关。如果您正在使用某些框架(即 MFC/ATL),您通常会找到一些辅助基础设施。此回复指的是 WINdows 中的最低 API 级别。如果您打算使用 MFC,请看这里,如果您更喜欢 ATL,请看这里。
回答by X-Istence
There is no cross-platform way to do this in C++
在 C++ 中没有跨平台的方法来做到这一点
Now that we have that out of the way, Felice Pollano'sanswer provides the Windows API so you can manipulate the clipboard in Windows.
现在我们已经解决了这个问题,Felice Pollano 的答案提供了 Windows API,因此您可以在 Windows 中操作剪贴板。
Appleprovides an example application named ClipboardViewerand an entire reference to the NSPasteBoardand the functionality it provides.
Apple提供了一个名为ClipboardViewer的示例应用程序以及对NSPasteBoard及其提供的功能的完整参考。
As for Linux, it depends on what windowing manager you are running.
对于 Linux,这取决于您正在运行的窗口管理器。
回答by Akiva
There is a cross platform way to do this in C++, provided you are willing to use the Qt Library.
如果您愿意使用 Qt 库,则在 C++ 中有一种跨平台的方法可以做到这一点。
A solution for this is provided here:
这里提供了一个解决方案:
回答by John Smith Images
If you are looking for a simle way to do this : simulate the keyboard combination ctrl + v and you are done with it. On all platforms.
如果您正在寻找一种简单的方法来做到这一点:模拟键盘组合 ctrl + v 就可以了。在所有平台上。