GetAsHandle (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following code locks the memory for text on the Clipboard, then reads the text.

Code

#include <Clipbrd.hpp>

void __fastcall TForm1::Button1Click(TObject *Sender)
{
int TextHandle;
PChar pText;

Clipboard()->Open();
try
{
  TextHandle = Clipboard()->GetAsHandle(CF_UNICODETEXT);
  pText = (PChar)GlobalLock((HGLOBAL)TextHandle);
  ListBox1->Items->Add(StrPas(pText));
  GlobalUnlock((HGLOBAL)TextHandle);
}
catch (...)
{
  Clipboard()->Close();
  throw;
}
Clipboard()->Close();
}

Uses