Converting Between OLE_COLOR and COLORREF Types

Last reviewed: October 12, 1995
Article ID: Q131101
The information in this article applies to:
  • Microsoft OLE Control Developer's Kit (CDK) versions 1.0 and 1.1

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;
   }

REFERENCES

For a complete list of the translations performed by OleTranslateColor(), or for more information about the OLE_COLOR type, please see the "Microsoft OLE Control Developer's Kit User's Guide and Reference," Appendix D: OLE Controls Architecture, under the heading "Standard Color Type."


Additional reference words: kbinf 1.00 1.10
KBCategory: kbole kbprg kbcode
KBSubcategory: CDKIss


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: October 12, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.