2013年5月25日土曜日

フォームアプリケーションで再生



Windows フォームアプリケーションを作成する。
ボタンをひとつ貼り付けてクリックハンドラにコードを貼り付ける

  1. #pragma once  
  2.   
  3. #include <dshow.h>  
  4.   
  5. namespace aviPleayetForm {  
  6.   
  7.  using namespace System;  
  8.  using namespace System::ComponentModel;  
  9.  using namespace System::Collections;  
  10.  using namespace System::Windows::Forms;  
  11.  using namespace System::Data;  
  12.  using namespace System::Drawing;  
  13.   
  14.  /// <summary>  
  15.  /// Form1 の概要  
  16.  /// </summary>  
  17.  public ref class Form1 : public System::Windows::Forms::Form  
  18.  {  
  19.  public:  
  20.   Form1(void)  
  21.   {  
  22.    InitializeComponent();  
  23.    //  
  24.    //TODO: ここにコンストラクター コードを追加します  
  25.    //  
  26.   }  
  27.   
  28.  protected:  
  29.   /// <summary>  
  30.   /// 使用中のリソースをすべてクリーンアップします。  
  31.   /// </summary>  
  32.   ~Form1()  
  33.   {  
  34.    if (components)  
  35.    {  
  36.     delete components;  
  37.    }  
  38.   }  
  39.  private: System::Windows::Forms::Button^  button1;  
  40.  protected:   
  41.   
  42.  private:  
  43.   /// <summary>  
  44.   /// 必要なデザイナー変数です。  
  45.   /// </summary>  
  46.   System::ComponentModel::Container ^components;  
  47.   
  48. #pragma region Windows Form Designer generated code  
  49.   /// <summary>  
  50.   /// デザイナー サポートに必要なメソッドです。このメソッドの内容を  
  51.   /// コード エディターで変更しないでください。  
  52.   /// </summary>  
  53.   void InitializeComponent(void)  
  54.   {  
  55.    this->button1 = (gcnew System::Windows::Forms::Button());  
  56.    this->SuspendLayout();  
  57.    //   
  58.    // button1  
  59.    //   
  60.    this->button1->Location = System::Drawing::Point(13, 228);  
  61.    this->button1->Name = L"button1";  
  62.    this->button1->Size = System::Drawing::Size(75, 23);  
  63.    this->button1->TabIndex = 0;  
  64.    this->button1->Text = L"button1";  
  65.    this->button1->UseVisualStyleBackColor = true;  
  66.    this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);  
  67.    //   
  68.    // Form1  
  69.    //   
  70.    this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);  
  71.    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;  
  72.    this->ClientSize = System::Drawing::Size(284, 263);  
  73.    this->Controls->Add(this->button1);  
  74.    this->Name = L"Form1";  
  75.    this->Text = L"Form1";  
  76.    this->ResumeLayout(false);  
  77.   
  78.   }  
  79. #pragma endregion  
  80.  private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {  
  81.      IGraphBuilder *pGraph = NULL;  
  82.      IMediaControl *pControl = NULL;  
  83.      IMediaEvent   *pEvent = NULL;  
  84.   
  85.      // COM ライブラリを初期化する。  
  86.      HRESULT hr = CoInitialize(NULL);  
  87.      if (FAILED(hr))  
  88.      {  
  89.       printf("ERROR - Could not initialize COM library");  
  90.       return;  
  91.      }  
  92.   
  93.      // フィルタ グラフ マネージャを作成し、インターフェイスを問い合わせる。  
  94.      hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,   
  95.       IID_IGraphBuilder, (void **)&pGraph);  
  96.      if (FAILED(hr))  
  97.      {  
  98.       printf("ERROR - Could not create the Filter Graph Manager.");  
  99.       return;  
  100.      }  
  101.   
  102.      hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);  
  103.      hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);  
  104.   
  105.      // グラフを作成する。 重要 : この文字列をシステム上のファイルに置き換える。  
  106.      hr = pGraph->RenderFile(L"E:\\sampleMovie\\avi_divx5_mp3.avi", NULL);  
  107.      if (SUCCEEDED(hr))  
  108.      {  
  109.       // グラフを実行する。  
  110.       hr = pControl->Run();  
  111.       if (SUCCEEDED(hr))  
  112.       {  
  113.        // 完了するまで待機する。  
  114.        long evCode;  
  115.        pEvent->WaitForCompletion(INFINITE, &evCode);  
  116.   
  117.        // 注 : 実際のアプリケーションでは INFINITE を使用しないこと。  
  118.        // 無期限にブロックする場合がある。  
  119.       }  
  120.      }  
  121.      pControl->Release();  
  122.      pEvent->Release();  
  123.      pGraph->Release();  
  124.     }  
  125.  };  
  126. }  


プロジェクトの変更

「プロジェクト(P)」→「***のプロパティ(P)」→「構成プロパティ」→「リンカ」→「入力」で 「追加の依存ファイル」を追加
「親またはプロジェクトの規定値から継承」 をチェック


「プロジェクト(P)」→「***のプロパティ(P)」→「構成プロパティ」→「全般」で 共通ランタイム サポートを変更
純粋MSIL共通言語ランタイム(/clr:pure) ⇒ 共通言語ランタイム(/clr)


0 件のコメント:

コメントを投稿