256-Color Support in OLE 2.0 Containers

Last reviewed: May 24, 1995
Article ID: Q98872
The information in this article applies to:
  • Microsoft OLE Libraries for Windows and Win32s, version 2.0
  • Microsoft OLE Libraries, included with:

        - Microsoft Windows NT, versions 3.5 and 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 reference words: 1.00 2.00 3.50 4.00 95
KBCategory: kbole kbprg
KBSubcategory: LeTwoPrs


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 24, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.