如何检索复制的文本(使用 CTRL + C 命令)

How to retrive text that was copied (with the CTRL + C command)

我有一个用 C++ 编写的 Windows 应用程序。我想添加一个粘贴选项,以便应用程序可以根据请求检索用户之前复制的任何文本(即使用 control-C 命令)。

有办法吗?

您需要使用函数 OpenClipboard()GetClipboardData()CloseClipboard()

来自 MSDN:

Pasting Information from the Clipboard

  1. Open the clipboard by calling the OpenClipboard function.

  2. Determine which of the available clipboard formats to retrieve.

  3. Retrieve the handle to the data in the selected format by calling the GetClipboardData function.

  4. Insert a copy of the data into the document.

    The handle returned by GetClipboardData is still owned by the clipboard, so an application must not free it or leave it locked.

  5. Close the clipboard by calling the CloseClipboard function.