Window Media Player

Source: Internet
Author: User
Tags transparent color

 

Window Media Player Favorites

I saw a post on the forum today and learned it by the way.

 

Http://topic.csdn.net/u/20090818/14/ea5abcf0-1897-4282-b39c-58fbb21b4c33.html? 38882

 

 

Websites provided by many friends:

 

Design of Digital Video Player: http://www.pcdog.com/edu/vc/2005/12/j057824.html with vc6.0

 

 

Implementation of a small project:

 

 

Http://download.csdn.net/source/1585136

 

 

[Open-source] Graphic tutorial on playing music with the Windows Media Player control (MP3, WAV, WMV)

 

Http://www.bccn.net/Article/net/cs/jszl/200709/6438.html

 

 

 

Use Media Player to design personalized media players:

 

Http://dev.yesky.com/SoftChannel/72342371928702976/20040922/1856774.shtml

 

Finally, this website always automatically returns to the home page, so the content is reprinted.

 

 

[Article Information]
 
Author: Longgrui, Qingdao branch, 22nd Research Institute, Electronic Technology Group Corporation
Time: 2004-09-22
Source: Skynet
Edit responsibility: Ark
 
[Document Introduction]
 
This article mainly introduces how to use the Windows Media Player control and completes the design and implementation of the personalized Media Player program.

Abstract: This article mainly introduces how to use the Windows Media Player control and completes the design and implementation of the personalized Media Player program.

Keywords: ActiveX control; Multimedia; form translucent; hotkey

Introduction

Multimedia playback software has become a required installation software for almost every home computer. It is popular with RealOne Player, Windows Media Player, and Kingsoft, a domestic software, using these software, you can play multiple formats of multimedia files, such as RM, rmvb, MP3, MPEG, and dat. Although these commercial software has been fully functional, it is difficult to adapt to the taste of every consumer because its product development is intended for most common consumers. As a programmer, we can use our technical advantages to transform it and design our own media playback software, after the transformation, the software will be used more in line with their own habits. This article uses Windows Media Player 9.0 as an example to describe how to transform it into a personalized Media Player software.

Basic control over the Windows Media Player Control

After Windows Media Player 9.0 is installed, a Windows Media Player ActiveX control is installed on the system and registered. This control provides developers with a vast majority of the features of Windows Media Player 9.0. It allows developers to easily implement secondary development of Windows Media Player 9.0.

To use this control, you must first add it to the project. Click "add to project" under "project" to bring up "components and controls ..." Sub-menu, and enter the "registered ActiveX controls" directory in the pop-up dialog box to find and add the Windows Media Player control to the project. 17 classes starting with cwmp will be added to the project. In the resource view, drag the control to the dialog box used to play multimedia and use classwizard to associate the control with the cwmpplayer4. Cwmpplayer4 provides basic methods for interacting with the Windows Media Player control, and some member functions can further obtain instances of other related class objects. The seturl () and close () methods can open and close specified media files. After opening the file, you can use the button on the control to control the play, pause, stop, and volume of the media. To control media playback in a program, you can use the getcontrols () function to return the cwmpcontrols Class Object and call the play (), stop (), pause (), fastforward (), fastreverse () and other methods to complete the playing, stop, pause, fast forward, fast return and other corresponding actions; if you need to set and change the control properties in the program, you can use the getsettings () method to return a cwmpsettings Class Object and use its member function to complete the corresponding settings. For example, the following code sets the playback volume to the maximum:

 

 

M_setting = m_wmpplayer.getsettings ();
M_setting.setvolume (100 );

Currently, you only play the media in window mode. Most media playing software provides full-screen playback. Windows Media Player is no exception. You only need to call the cwmpplayer4 member function setfullscreen () with the parameter true () in full screen mode, you can click the left mouse or right-click the menu to return to the window playback mode. You can use cwmpplayer4, cwmpsettings, cwmpcontrols, and other classes to implement most common features of Windows Media Player. If you need further control, you can use the following functions to return related class objects and call related member functions for implementation:

Getcurrentmedia () returns the cwmpmedia Class Object

Getmediacollection () returns the cwmpmediacollection Class Object

Getplaylistcollection () returns the cwmpplaylistcollection Class Object

Getnetwork () returns the cwmpnetwork Class Object

Getcurrentplaylist () returns the cwmpplaylist Class Object

Getcdromcollection () returns the cwmpcdromcollection Class Object

Getclosedcaption () returns the cwmpclosedcaption Class Object

Geterror () returns the cwmperror Class Object

Getdvd () returns the cwmpdvd Class Object

Getplayerapplication () returns the cwmpplayerapplication Class Object

 

 

Hotkey hiding and calling

The conventional functions described earlier are available in Windows Media Player. In order to make the designed program more suitable for you, you can add some personalized features that Windows Media Player does not have as needed. For example, the hotkeys to be added below this program can be quickly hidden, the outgoing call function and the adjustable translucent playback function are not available in Windows Media Player, and I will try it out during this time, both functions are quite practical. Of course, since the "personalized" function is to be added here, you should decide what features to add based on your personal preferences. The purpose of this article is only to introduce others.

Mainstream media playing software, such as Kingsoft film overlord, RealOne Player, and Windows Media Player, do not provide a completely hidden function. Generally, it can only be minimized but reduced to a small icon in the task area, in this way, the hidden effect is not achieved. If you leave the computer temporarily, others can easily open the currently running media playing program. The purpose is to hide the main program form, the taskbar, And the Alt + Tab key during inter-program switching. In this way, after the program is hidden, others will not be aware of the program execution, which can achieve very good Stealth Effect. As there is no window for user interaction after hiding, you need to add a hotkey to hide the program and call it out from the background.

First, register a hotkey in the program. no matter whether the program runs on the foreground or the background, as long as the user presses the hotkey, the program will immediately switch between the front and back ends. The following code is executed during the initial running of the program. It is used to register the hidden hotkey Ctrl + P (or Ctrl + p) by calling registerhotkey) and the hot key Ctrl + Shift + a (or Ctrl + Shift + a) used for Program Calling ):

// Register the hotkey
Hwnd = getsafehwnd ();
Registerhotkey (hwnd, 1001, mod_control | mod_shift, 'A ');
Registerhotkey (hwnd, 1002, mod_control | mod_shift, 'A ');
Registerhotkey (hwnd, 1003, mod_control, 'P ');
Registerhotkey (hwnd, 1004, mod_control, 'P ');

Among them, parameters such as 1001 and 1002 are the IDS corresponding to these hot keys. After the program captures the hotkey message wm_hotkey, it uses these IDs to confirm which key is pressed. Classwizard does not encapsulate the message wm_hotkey. You need to manually add the ing and processing of the message. The wparam parameter of the message processing function contains the key ID. The following is the implementation code:

Switch (wparam ){
Case 1001:
Case 1002:
{
// Outbound call program
Hwnd = getsafehwnd ();
Long lstyle =: getwindowlong (m_hwnd, gwl_style );
Lstyle & = ~ Ws_popup;
: Setwindowlong (m_hwnd, gwl_style, lstyle );
: Showwindow (m_hwnd, sw_show );
Cwnd: setforegroundwindow ();
M_control.play (); // continue
Break;
}
Case 1003:
Case 1004:
{
// Hide the program
// Hide the program
Hwnd = getsafehwnd ();
Long lstyle =: getwindowlong (m_hwnd, gwl_style );
Lstyle | = ws_popup;
: Setwindowlong (m_hwnd, gwl_style, lstyle );
: Showwindow (m_hwnd, sw_hide );
M_control.pause (); // pause
Break;
}
}

When hiding a form, you first get the current window style through getwindowlong (). Then, append the ws_popup style and set it by setwindowlong (). The modified form will have the same style as the toolbar, that is, the form will not be displayed in the taskbar, and will not appear when you use Alt + TAB to switch the form. Finally, sw_hide calls the showwindow () function to hide the main window of the program. The form calling process is the opposite: After the getwindowlong () function obtains the current window style, it removes the ws_popup style and is set by setwindowlong () to restore the original style of the program, finally, sw_show is used to call the showwindow () function to display the main form of the program. Finally, the member function setforegroundwindow () of the cwnd class displays the calling program to the foreground.

Note that the previously registered hotkey must be deregistered before exiting the program, and completed by the unregisterhotkey () function:

Hwnd = getsafehwnd ();
Unregisterhotkey (hwnd, 1001 );
Unregisterhotkey (hwnd, 1002 );

 

 

 


 

Form translucent effect implementation

The form translucent feature is actually added to meet the "one-in-one" purpose. I usually read e-books when playing media files, and set the playing software to always occupy a large area of the screen and block a lot of text, making reading inconvenient. Therefore, we have the idea of setting the playback software interface to translucent.

In traditional Windows applications, to achieve a translucent effect, you need to process the wm_paint message window of your own window, which is troublesome. A new API function setlayered;wattributes () is provided in Windows 2000 and later versions. It can easily set the form to a translucent effect. Its function declaration is as follows:

Bool setlayeredwindowattributes (
Hwnd, // handle to the layered window
Colorref crkey, // specifies the Color Key
Byte balpha, // value for the blend function
DWORD dwflags // action
);

Dwflags has two settings: lwa_alpha and lwa_colorkey. If lwa_alpha is set, balpha is used to determine the transparency. If lwa_colorkey is set, the transparent color is specified as the crkey, other colors are displayed normally. To be able to use this function, you must add a pre-defined statement before:

# Define ws_ex_layered 0x00080000

After loading the user32.dll module with getmodulehandle () and calling getprocaddress (), you can get the pointer of setlayeredwindowattributes () in user32.dll and set the form to translucent through the setlayeredwindowattributes () function:

// Global variable
Typedef bool (winapi * lpfn) (hwnd, colorref Cr, byte balpha, DWORD dwflags );
Lpfn g_psetlayeredwindowattributes;
......
// Obtain the pointer of setlayeredwindowattributes in user32.dll.
Hmodule huser32 = getmodulehandle (_ T ("user32.dll "));
G_psetlayeredwindowattributes = (lpfn) getprocaddress (huser32, "setlayeredwindowattributes ");
If (g_psetlayeredwindowattributes = NULL)
: Postquitmessage (0 );
......
// Translucent
Hwnd = getsafehwnd ();
Long lwindowlong = getwindowlong (hwnd, gwl_exstyle) | ws_ex_layered;
: Setwindowlong (hwnd, gwl_exstyle, lwindowlong );
G_psetlayeredwindowattributes (hwnd, 0, (byte) m_sldalpha.getpos (), 2 );
: Redrawwindow (hwnd, null, null, rdw_erase | rdw_invalidate | rdw_frame | rdw_allchildren );

To control the transparency of the form, you can add a slider control to control the form. After such processing, you can continue to read the blocked text while playing the media without interrupting it.

Summary

In this article, the use of the Windows Media Player control is used to implement the general functions of the Windows Media Player 9.0 media playback software, the general method of personalized programming is introduced in the following example: Hot Key hiding, outgoing form and form translucent settings. Readers can write personalized media playing programs that support other media formats by using controls provided by other software, such as RealPlayer, as needed. The program described in this article is compiled and debugged by Microsoft visaul c ++ 2000 under Windows 6.0 professional. To run the program, you must install Windows Media Player 9.0 in advance.

 

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.