Microsoft KB Archive/131101

= Converting Between OLE_COLOR and COLORREF Types =

Article ID: 131101

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft OLE Control Developer's Kit (CDK)

-



This article was previously published under Q131101



SUMMARY
This article shows by example how to use the COleControl::TranslateColor method can be used to convert an OLE_COLOR value into a COLORREF value by using the cast operator.



MORE INFORMATION
The main difference between an OLE_COLOR and a COLORREF is that if an OLE_COLOR has its high-order bit set, the low-order byte is treated as a system color index. The function OleTranslateColor, which is called by COleControl::TranslateColor, translates the system color index into a COLORREF when this condition is detected. The following code illustrates conversion between an OLE_COLOR and a COLORREF: void CMyOleControl::ConversionTest {

OLE_COLOR ocBack = GetBackColor;

// Convert OLE_COLOR to COLORREF COLORREF clrBack = TranslateColor(ocBack);

// Convert COLORREF to OLE_COLOR OLE_COLOR ocConverted = (OLE_COLOR)clrBack; }

