2016-08-02 9 views
-1

私はWindows Media PlayerをCプログラムに埋め込んでいます。 WMP SDKのC++でWMP Hostのサンプルが見つかりました。これには、ディスパッチャが含まれています。しかし、イベントを受け取ったときに、どのようにイベントを送信したのか、そのクラスオブジェクトの変数にどのようにアクセスすればよいのでしょうか?たとえば、クラスメンバ(変数)を設定したり、メソッドを呼びたいとします。WMP EventDispatcher:誰がイベントを送信したかを知る方法?

CWMPHostオブジェクトは、WMPのオブジェクトを含むウィンドウを作成し、イベントオブジェクトを作成します。最小限のコードは次のとおりです。

LRESULT CWMPHost::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 
{ 
    AtlAxWinInit(); 
    CComPtr<IAxWinHostWindow>   spHost; 
    CComPtr<IConnectionPointContainer> spConnectionContainer; 
    CComWMPEventDispatch    *pEventListener = NULL; 
    CComPtr<IWMPEvents>     spEventListener; 
    HRESULT        hr; 
    RECT        rcClient; 

    m_dwAdviseCookie = 0; 

    // create window 
    GetClientRect(&rcClient); 
    m_wndView.Create(m_hWnd, rcClient, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, 0); 

    // load OCX in window 
    hr = m_wndView.QueryHost(&spHost); 
    hr = spHost->CreateControl(CComBSTR(_T("{6BF52A52-394A-11d3-B153-00C04F79FAA6}")), m_wndView, 0); 
    hr = m_wndView.QueryControl(&m_spWMPPlayer); 

    // start listening to events 
    hr = CComWMPEventDispatch::CreateInstance(&pEventListener); 
    spEventListener = pEventListener; 

    hr = m_spWMPPlayer->QueryInterface(&spConnectionContainer); 

    // See if OCX supports the IWMPEvents interface 
    hr = spConnectionContainer->FindConnectionPoint(__uuidof(IWMPEvents), &m_spConnectionPoint); 
    if (FAILED(hr)) 
    { 
     // If not, try the _WMPOCXEvents interface, which will use IDispatch 
     hr = spConnectionContainer->FindConnectionPoint(__uuidof(_WMPOCXEvents), &m_spConnectionPoint); 
    } 
    hr = m_spConnectionPoint->Advise(spEventListener, &m_dwAdviseCookie); 

    return 0; 
} 

完全なサンプルコードはhttps://github.com/pauldotknopf/WindowsSDK7-Samples/tree/master/multimedia/WMP/cpp/WMPHost

+0

は、うーん...私はダウンの投票と密接な提案を参照してください、しかし、誰が何をすべきか私を助けたり、私に教えてくださいだろうか? –

+0

イベントを生成したWMPであったと見なすことができます。他に誰もしません。ハンスアンパッサン@ –

+0

は、私は積極的に複数のプレーヤーを持っているつもりなので、私は1知っている必要があります。あなたがIWMPEventsを実装するために使用 –

答えて

0

EDITで見つけることができます:私はインクルード依存関係をuntangledと適用

まず:私のニーズを満たしている私の改善ソリューション円形インクルーシブに対する警備員。 CWMPHostクラス定義CWMPEventDispatchクラスについて知る必要はありません。しかし、その実装はありませんので、CWMPEventDispatch.hクラス定義がなく、CWMPHost.hファイルにCWMPHost.cppファイルに含まれています。

これは所有CWMPHostオブジェクトへのポインタであることがCWMPEventDispatchのメンバーを定義することができ:

CWMPHost *pCWMPHost; 

CWMPHost::Create方式に設定されている:ここで、イベントディスパッチャがアクセスできる

hr = CComWMPEventDispatch::CreateInstance(&pEventListener); 
    pEventListener->pCWMPHost= this; 

ディスパッチャを作成したオブジェクトのメソッドとメンバ。

関連する問題