Share via


IMAGE Sample: Creates an ActiveX Control That Downloads Asynchronously

The IMAGE sample demonstrates how to use MFC to build an ActiveX control that is capable of downloading data asynchronously. The control has a property based on the CDataPathProperty class.

The IMAGE control can display a bitmap image from a BMP file (but does not support BMP files with greater than 8-bit color depth, so files containing more than 256 colors cannot be displayed.) The ImagePath property of the control provides a path to the image. If the image is large and the download takes place over a slow link, the asynchronous support built into the CDataPathProperty object managing the path becomes active and renders the data to the control's painting code without blocking other processing.

The control features a simple property page that gives access to the ImagePath property as well as the AutoSize property. The AutoSize property, if set to TRUE, automatically snaps the size of the control to the size of the image it contains. If the AutoSize property is FALSE, the automatic sizing is disabled.

The image control also implements a read-only Boolean property named ReadyState. ReadyState is TRUE if the control has successfully read and presented all the data in the image stream. ReadyState is FALSE until the control is fully initialized.

See Controls Samples for details on adding a control to the Toolbox, manually registering a control, and using the ActiveX Control Test Container.

Note

Some of the samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

Security noteSecurity Note

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

See Also

Other Resources

MFC Samples