Microsoft KB Archive/98872

= 256-Color Support in OLE 2.0 Containers =

Article ID: 98872

Article Last Modified on 12/3/2003

-

APPLIES TO

 Microsoft OLE 2.0 Microsoft OLE 4.0, when used with:  Microsoft Windows NT 4.0

 Microsoft Windows NT 3.51 Service Pack 5

 Microsoft Windows 95 </li></ul>

-

<div class="notice_section">

This article was previously published under Q98872

<div class="summary_section">

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.

<div class="moreinformation_section">

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: kbprogramming KB98872

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.