0

As the topic, i know that is a way to get clipboard text but i wanna get the data from clipboard only when user click copy or trigger CTRL+C.

I found this X11 Wait for and Get Clipboard Text but isn't for windows.

I tried also that but the result doesn't satisfy me.

std::string GetClipboardText() {
  // Try opening the clipboard
  if (! OpenClipboard(nullptr))
    ... // error

  // Get handle of clipboard object for ANSI text
  HANDLE hData = GetClipboardData(CF_TEXT);
  if (hData == nullptr)
    ... // error

  // Lock the handle to get the actual text pointer
  char * pszText = static_cast<char*>( GlobalLock(hData) );
  if (pszText == nullptr)
    ... // error

  // Save text in a string class instance
  std::string text( pszText );

  // Release the lock
  GlobalUnlock( hData );

  // Release the clipboard
  CloseClipboard();

  return text;
 }
sectasy
  • 98
  • 2
  • 8
  • Short answer: this will be useful [SetClipboardViewer function (winuser.h) - Win32 apps | Microsoft Docs](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setclipboardviewer) – MikeCAT Nov 16 '20 at 14:03
  • I have no idea how to use it, Can you give me an example? I would be grateful – sectasy Nov 16 '20 at 14:08

0 Answers0