Windows Media Player application sample code analysis (mobile 6.5.3)

Source: Internet
Author: User

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

1. Download exampleCode

You can find the sample code from the example "Windows Mobile 6.5.3 dtk \ samples \ pocketpc \ CPP \ ATL \ wmpsample" in the example of mobile 6.5.3 professional dtk.

2. Prepare the development environment

My development environments

OS:Windows 7

SDK:Windows Mobile 6.5.3 professional dtk

Development Environment:Visual Studio 2008

3. Deploy and run in the simulator

3.1 open the properties page of Solution "wmpsample" and click "Configuration Manager" to modify the deployed platform.

Modify the deployment device to Windows Mobile 6.5.3 professional emulator.

3.2 regenerate and run the solution. Running result

4. parse the solution for implementing the player

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

The main message processing function is in this CPP.

4.2.1 process creat messages

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_app1_1_m_wmplayer.create (hwnd, rcclient, text ("{6bf52a52-394a-11d3-b153-00c04f79faa6 }"),
Ws_child | ws_visible | ws_border, 0 );
CBR (_ atlmodule. m_app1_1_m_wmplayer.m_hwnd! = NULL );

HR = _ atlmodule. m_app1_1_m_wmplayer.querycontrol (& (_ atlmodule. m_app1_1_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 process opened messages

Main functions: In the pop-up dialog box, select a file and play it back.

A) Select a file

Openfilenameex ofn;

Tchar szfilename [_ max_path]; // name of the opened file

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 ));

// Close the dialog of the selected file
Enddialog (hwnd, idok );

B) Play
HR = _ atlmodule. m_app1_1_m_spwmpplayer-> put_url (ccombstr (szfilename ));

4.2.3 process the playback and paused messages of Control Files

_ atlmodule. m_appwindow.m_spwmpplayer-> get_controls (& spwmpcontrols);
If (fplaypause)
{< br> spwmpcontrols-> pause ();
}< br> else
{< br> spwmpcontrols-> play ();
}< br> fplaypause =! Fplaypause;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.