The information in this article applies to:
SUMMARY
MimeType.exe demonstrates the steps necessary to register an ActiveX object
as the default player for a MIME type and to receive the file name of the
file to be played. Mimetype.exe is an MFC sample that creates an ActiveX
control and registers it as the default player for a MIME type. It also
illustrates how to handle the calls that Internet Explorer makes when
sending the URL of the file to play.
or the following OBJECT tag:
or the user clicks on a link to a file with the .mtp extension:
Internet Explorer launches the registered component and passes Test.mtp's
path to it as a property.
MORE INFORMATIONThe following file is available for download from the Microsoft
Download Center. Click the file name below to download the file: Mimetype.exeFor more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. PurposeMimetype.exe is an MFC sample that creates an ActiveX control and registers it as the default player for a MIME type. It also illustrates how to handle the calls that Internet Explorer makes when sending the URL of the file to play. The sample has been built and tested with Visual C++ on Intel platforms.MIME Type PlayersThere are three situations where Internet Explorer (IE) uses MIME type players: when IE sees an EMBED tag in HTML; when a link is accessed either by clicking a hyperlink or by typing a URL in the address bar; and when IE sees an OBJECT tag in HTML when there is no CLASSID attribute but there is a MIME TYPE attribute specified.In the case of the EMBED tag, the player associated with the MIME type of the SRC attribute URL is looked up. If a player exists, it is created within the current page with dimensions specified in the EMBED tag. The SRC URL is then passed to the player. Similarly, when a new URL is navigated to, the player associated with the target URL is determined. If a player exists, it is loaded in the destination page and the URL is passed to the player. The dimensions of the player always are full size of the destination frame. In the case of an OBJECT tag with no CLASSID attribute but with a MIME TYPE attribute, the player associated with the MIME TYPE attribute is looked up. If a player exists, it is created within the current page with dimensions specified in the OBJECT tag. The SRC URL is then passed to the player. It is important to note that in each case the file to play is not downloaded by Internet Explorer. It is up to the player to download the file or interact with it in any way it sees fit. Registering as a PlayerIn order for an ActiveX component to act as the default MIME type player, it must have the following registry entries:
Receiving the URL to PlayIn all cases Internet Explorer passes the URL of the file to play to the default player via the IPropertyBag interface. That is, when Internet Explorer launches a player, it creates an instance of IPropertyBag and loads the "SRC" property with the URL of the file to play. Then it queries the player for IPersistPropertyBag and sends it the IPropertyBag instance through IPersistPropertyBag::Load.In MFC, this manifests itself as a property exchange so you can load the "SRC" property directly in your override of DoPropExchange. The following code is from the sample CMimetypeCtrl::DoPropExchange method (in mtpctl.cpp):
This gets the string property from the property bag and puts it into a
CString member.
NOTE: If you are using the ActiveX Designer Framework (basectl in the ActiveX SDK), you get an override called LoadTextState that gets called from the framework's implementation of IPersistPropertyBag. You can call IPropertyBag::Read to get the "SRC" property. Downloading the FileInternet Explorer does not download the file before sending the URL to the player. The player is responsible for retrieving the file and playing it. There are a number of ways to handle this depending on what the player needs to do. One way is illustrated in the sample with the URLDownloadToCacheFile function. This function downloads the file only if necessary and returns the name of the local cached copy of the file. It should be noted that URLDownloadToCacheFile is a blocking function. Even though the data is downloaded asynchronously the function does not return until all the data is downloaded.If complete asynchronous downloading is desired, one of the other UOS functions, such as URLOpenStream, or perhaps general URL monikers would be more appropriate. The following code is taken from CMimetypeCtrl::DoPropExchange (in Mtpctl.cpp) and fills up the string m_cstrCacheFileName with the complete path of the local file:
Running the SampleMimetype.exe is a self-extracting executable that you can expand to install the project files for the Mimetype control. Build the sample with Visual C++ 5.0 using the supplied Mimetype.dsw project file. The control is automatically be registered as part of the build process. You can then load the sample Test.htm into your browser.The result of this should be two instances of the mimetype control loaded in the current page. The control displays as a rectangle with the name of the URL (Test.mtp) and the name of the local file (<path>\Test.mtp). The sample page also contains a link. Clicking on the link brings up a new page with the control loaded full frame displaying the same URL information. The reason the supplied URL and the local file path are the same is that the URLDownloadToCacheFile function returns the full path of the supplied URL if it is a local (file:) URL. If the SRC URL in the EMBED and OBJECT tags or the destination of the link were a remote file (http:, ftp:), then the local file path would contain the full path of the cached copy of the remote file. NOTE: The Mimetype control created by the sample project is not digitally signed. Because of this, depending on the current IE security settings, IE might either fail to instantiate the control or will warn before loading the control. If the IE security settings are set to High, IE will not load the sample control. To allow the control to be instantiated the IE security level must be set to either Medium or Low for the zone where the control is being loaded from. To set the security level in IE select the View menu and then the Internet Options menu item, choose the Security tab. Select either Medium or Low as the security level for the zone where the sample page is coming from. Additional query words:
Keywords : kbfile kbinterop kbsample kbIE500 |
Last Reviewed: December 4, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |