Easily Learn To Use The Clipboard In Modern C++ On Windows
February 24, 2021 By Yilmaz Yoru
Для просмотра ссылки Войдиили Зарегистрируйся, also called as the paste buffer, is is a buffer which operating systems provide to copy things (texts, bitmaps, tables etc.) for short term and transfer within and between application programs. The clipboard is usually temporary and unnamed, and its contents reside in the computer’s memory.
In C++ Builder, you can use clipboard copy and paste event easily in VCL applications. There is a good example in here Для просмотра ссылки Войдиили Зарегистрируйся
Let’s summarize some simple VCL and FMX copy and paste operations on texts and on bitmaps.
You can copy or paste Text by using clipboard() class as below
You can copy or paste Bitmaps by using clipboard() class as below,
You can do more advanced things by using Clipboard(), There are many components using clipboard properties.
In FireMonkey applications you need to use PlatformServices (TPlatformServices) to copy or paste things.
Copying Text to Clipboard
Copying Image to Clipboard
Paste Text from Clipboard
Copying Image to Clipboard
February 24, 2021 By Yilmaz Yoru
Для просмотра ссылки Войди
In C++ Builder, you can use clipboard copy and paste event easily in VCL applications. There is a good example in here Для просмотра ссылки Войди
Let’s summarize some simple VCL and FMX copy and paste operations on texts and on bitmaps.
Using Clipboard in C++ Builder VCL Applications
In C++ Builder VCL applications you must include clipbrd.hpp
Код:
#include <vcl.h>
#include <clipbrd.hpp>
Код:
TStringList *strlist= new TStringList();
// Copy StringList Text to Clipboard
Clipboard()->AsText = strlist->Text;
// Paste Text from Clipboard to StringList
strlist->Text = Clipboard()->AsText;
Код:
TBitmap *bmp = new TBitmap();
// Copy Bitmap to Clipboard
Clipboard()->Assign(bmp);
// Paste Bitmap from Clipboard
bmp->Assign(Clipboard());
Using Clipboard in C++ Builder FireMonkey Applications
In C++ Builder FMX applications clipboard is available from IFMXClipboardService. There is FMX.clipboard.hpp header you can use.
Код:
#include <fmx.h>
#include <FMX.clipboard.hpp>
Copying Text to Clipboard
Код:
_di_IFMXClipboardService service;
if(TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXClipboardService)) &&
(service = TPlatformServices::Current->GetPlatformService(__uuidof(IFMXClipboardService))))
{
UnicodeString ustr = L"ABCDEFG";
service->SetClipboard(TValue::_op_Implicit(ustr));
}
Код:
_di_IFMXClipboardService service;
if(TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXClipboardService)) &&
(service = TPlatformServices::Current->GetPlatformService(__uuidof(IFMXClipboardService))))
{
std::unique_ptr<TBitmap> Image(TextBorder->MakeScreenshot());
service->SetClipboard(TValue::_op_Implicit(Image.get()));
}
Код:
_di_IFMXClipboardService service;
if(TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXClipboardService)) &&
(service = TPlatformServices::Current->GetPlatformService(__uuidof(IFMXClipboardService))))
{
TValue value = service->GetClipboard();
if(!value.IsEmpty)
{
if(value.IsType<String>())
{
UnicodeString ustr = value.ToString();
}
}
}
Код:
_di_IFMXClipboardService service;
if(TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXClipboardService)) &&
(service = TPlatformServices::Current->GetPlatformService(__uuidof(IFMXClipboardService))))
{
TValue value = service->GetClipboard();
if(!value.IsEmpty)
{
if (value.IsType<TBitmapSurface*>())
{
std::unique_ptr<TBitmap> bitmap(new TBitmap());
bitmap->Assign(value.AsType<TBitmapSurface*>());
value.AsType<TBitmapSurface*>()->Free();
}
}
}