DRAWPIC: Extracting a Bitmap or Icon from an LPPICTUREDISP

Click to open or copy the DRAWPIC project files.

At times it may be necessary in an ActiveX Control to obtain the handle to an icon or bitmap contained in a LPPICTUREDISP structure. The DRAWPIC sample demonstrates how to get a handle to a bitmap or icon from a LPPICTUREDISP.

The important lines of code in this sample are:

// get handle of the bitmap
    NewPicture.m_pPict->get_Handle((OLE_HANDLE FAR *) &hBitmap);
// create a temporary bitmap
    CBitmap * TempBmp = CBitmap::FromHandle(hBitmap);
// get handle of the icon
    NewPicture.m_pPict->get_Handle((OLE_HANDLE FAR *) &hIcon);

Running the Sample

To run this sample, first compile, link, and register the control. Next, create an .exe test application using the Visual Basic project that ships with the sample. You can then step through the ActiveX Control code by setting the Visual Basic executable as the executable for the debug session.