How do you copy/paste from the clipboard in C++?

浪子不回头ぞ 提交于 2019-11-26 16:35:36

问题


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?


回答1:


In windows look at the following API:

  • OpenClipBoard
  • EmptyClipboard
  • SetClipboardData
  • CloseClipboard
  • GetClipboardData

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.




回答2:


There is no cross-platform way to do this in C++


Now that we have that out of the way, Felice Pollano's answer provides the Windows API so you can manipulate the clipboard in Windows.

Apple provides an example application named ClipboardViewer and an entire reference to the NSPasteBoard and the functionality it provides.

As for Linux, it depends on what windowing manager you are running.




回答3:


There is a cross platform way to do this in C++, provided you are willing to use the Qt Library.

A solution for this is provided here:

https://stackoverflow.com/a/40437290/2158002




回答4:


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.



来源:https://stackoverflow.com/questions/6436257/how-do-you-copy-paste-from-the-clipboard-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!