Udostępnij za pośrednictwem


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 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 provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

See Also

Other Resources

MFC Samples