Porady: pobieranie tekstu ze schowka (C++/CLI)
Następujący kod w przykładzie wykorzystano GetDataObject Członkowskich funkcja zwraca wskaźnik do IDataObject interfejsu.Ten interfejs może następnie badany pod kątem format danych i używane do pobierania danych rzeczywistych.
Przykład
// read_clipboard.cpp
// compile with: /clr
#using <system.dll>
#using <system.Drawing.dll>
#using <system.windows.forms.dll>
using namespace System;
using namespace System::Windows::Forms;
[STAThread] int main( )
{
IDataObject^ data = Clipboard::GetDataObject( );
if (data)
{
if (data->GetDataPresent(DataFormats::Text))
{
String^ text = static_cast<String^>
(data->GetData(DataFormats::Text));
Console::WriteLine(text);
}
else
Console::WriteLine("Nontext data is in the Clipboard.");
}
else
{
Console::WriteLine("No data was found in the Clipboard.");
}
return 0;
}