Windows Media Player Application Sample Code Analysis (Mobile 6.5.3)

來源:互聯網
上載者:User

The code named WmpSample demonstrates how to use the Windows Media Player ATL control from a Win32 application.

1. 下載範例程式碼 

您可以從http://msdn.microsoft.com/en-us/library/bb158713.aspx下載,也可以從安裝的Windows Mobile 6.5.3 Professional DTK帶的例子中“Windows Mobile 6.5.3 DTK\Samples\PocketPC\CPP\ATL\wmpsample” 找到此範例程式碼。

2. 開發環境準備

My Development Environments

OS Windows 7

SDK: Windows Mobile 6.5.3 Professional DTK

Development Environment: Visual Studio 2008

3. 部署並在模擬器中運行

    3.1 開啟解決方案“WMPSample”的屬性頁面,點擊“組態管理員”修改部署的平台

修改部署裝置為: Windows Mobile 6.5.3 Professional Emulator。

    3.2 重建解決方案,並運行。運行結果

4. 解析其實現播放器的解決方案

   4.1 wmpsample.cpp

        It contains initialization code for the application.

        If PreMessageLoop reutrn OK,then the program continuously runs with RunMessageLoop() and PostMessageLoop().

   4.2 MainWindow.cpp

主要實現的訊息處理功能就在此cpp中。

        4.2.1  處理Creat訊息

a) initilaize the menu bar

b) initialize WMP window
    AtlAxWinInit();  
    GetClientRect(hwnd, &rcClient);
    VERIFY(SystemParametersInfo(SPI_GETWORKAREA, 0, &rcMainWindow, 0));
    rcClient.bottom -= rcMainWindow.top;

c) create WMP control
    _AtlModule.m_appWindow.m_wmplayer.Create(hwnd, rcClient, TEXT("{6BF52A52-394A-11d3-B153-00C04F79FAA6}"),
                WS_CHILD | WS_VISIBLE | WS_BORDER, 0);
    CBR(_AtlModule.m_appWindow.m_wmplayer.m_hWnd != NULL);

    hr = _AtlModule.m_appWindow.m_wmplayer.QueryControl(&(_AtlModule.m_appWindow.m_spWMPPlayer));
    CHR(hr);

    hr = CComWMPEventDispatch::CreateInstance(&pEventListener);
    CHR(hr);

    spEventListener = pEventListener;       
    hr = _AtlModule.m_appWindow.m_spWMPPlayer->QueryInterface(&spConnectionContainer);
    CHR(hr);

4.2.1  處理檔案開啟的訊息

主要實現的功能:彈出對話方塊選擇檔案並播放

a)選擇檔案

    OPENFILENAMEEX  ofn;

    TCHAR           szFileName[_MAX_PATH]; //開啟的檔案名稱

    memset(&ofn, 0, sizeof(ofn)); // initialize structure to 0/NULL
    szFileName[0] = TEXT('\0');
    ofn.lStructSize = sizeof(ofn);
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = ARRAYSIZE(szFileName);
    ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_EXPLORER;
    ofn.lpstrFilter = TEXT("All Media files\0*.wma;*.mp3;*.mpeg;*.avi;*.wmv;*.asf;*.wav;*.mid;*.dvr-ms;*.mid;*.rmi;*.midi;*.wm;*.snd;*.au;*.aif;*.mpg;*.m1v;*.mp2;*.mpa\0");
    ofn.hwndOwner = hwnd;
    ofn.hInstance = _AtlBaseModule.GetResourceInstance();

    CBR(GetOpenFileNameEx(&ofn));

    //關閉選擇檔案的Dialog
    EndDialog(hwnd, IDOK);

b)播放
    hr = _AtlModule.m_appWindow.m_spWMPPlayer->put_URL(CComBSTR(szFileName));

4.2.3 處理控制檔案的播放和暫停訊息

           _AtlModule.m_appWindow.m_spWMPPlayer->get_controls(&spWMPControls);
           if (fPlayPause)
           {
               spWMPControls->pause();
           }
           else
           {
               spWMPControls->play();
           }
           fPlayPause = !fPlayPause;

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.