256-Color Support in OLE 2.0 Containers

ID: Q98872


The information in this article applies to:
  • Microsoft OLE Libraries for Windows and Win32s, version 2.0
  • Microsoft OLE Libraries, used with:
    • Microsoft Windows NT, versions 3.5, 3.51
    • Microsoft Windows 95


SUMMARY

If a client application draws a 256-color object in OLE version 1.0, the palette is always realized and used during the OleDraw command. As a result, the palette from the last object displayed is always used, causing previously drawn objects to update poorly.

In OLE version 2.0, OleDraw does not realize the palette automatically. Instead, a container must call IViewObject::GetColorSet() to retrieve the logical palette for each of its displayed objects. With this information, the container can construct a palette that best suits all of its displayed objects.


MORE INFORMATION

To get the equivalent of OLE 1.0 functionality in an OLE 2.0 container, IViewObject::GetColorSet must still be used to get a logical palette for an object, and in turn a palette must be created and realized from this information.

The following C++ function demonstrates the implementation of a drawing routine for an OLE 2.0 container that behaves similar to an OLE 1.0 client application.

Sample Code


void DrawObject(LPOLEOBJECT lpOleObject)
{
LPVIEWOBJECT lpViewObject;

    // Get a pointer to IViewObject.
    lpOleObject->QueryInterface(IID_IViewObject,
                                (LPVOID FAR *) &lpViewObject);

    // If the QI succeeds, get the LOGPALETTE for the object.
    if (lpView)
        lpView->GetColorSet(DVASPECT_CONTENT, -1, NULL, NULL, NULL,
                            &pColorSet);

    HPALETTE hPal=NULL;
    HPALETTE hOldPal=NULL;

    // If a LOGPALETTE was returned (not guaranteed), create the
    // palette and realize it. Note: A smarter application
    // would want to get the LOGPALETTE for each of its visible
    // objects, and try to create a palette that satisfies all of the
    // visible objects. Also, OleStdFree() is use to free the
    // returned LOGPALETTE.
    if ((pColorSet))
        {
        hPal = CreatePalette((const LPLOGPALETTE) pColorSet);
        hOldPal = SelectPalette(hDC, hPal, FALSE);
        RealizePalette(hDC);
        OleStdFree(pColorSet);
        }

    // Draw the object.
    OleDraw(m_lpOleObject, DVASPECT_CONTENT, hDC, &rect);

    // If we created a palette, restore the old one and destroy
    // the object.
    if (hPal)
        {
        SelectPalette(hDC,hOldPal,FALSE);
        DeleteObject(hPal);
        }

    // If a view pointer was successfully returned, it needs to be
    // released.
    if (lpView)
        lpView->Release();
} 

Additional query words: 1.00 2.00 3.50 4.00 95

Keywords : kbole kbprg kbNTOS350 kbNTOS351 kbOLE200 kbWinOS95 kbGrpCom kbDSupport
Version : :2.0
Platform : WINDOWS
Issue type :


Last Reviewed: October 26, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.