次の方法で共有


方法 : クリップボードからテキストを取得する

更新 : 2007 年 11 月

GetDataObject メンバ関数を使用して、IDataObject インターフェイスへのポインタを返す方法を次のコード例に示します。次に、このインターフェイスを使用してデータの形式を照会し、実際のデータを取得します。

使用例

// 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;
}

参照

その他の技術情報

C++ における Windows の操作

.NET プログラミング ガイド