home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / directx2 / sdk / samples / viewer / color.cpp next >
Encoding:
C/C++ Source or Header  |  1996-05-28  |  1.3 KB  |  50 lines

  1. /*==========================================================================
  2.  *
  3.  *  Copyright (C) 1995, 1996 Microsoft Corporation. All Rights Reserved.
  4.  *
  5.  *  File: color.cpp
  6.  *
  7.  ***************************************************************************/
  8.  
  9. #include "d3drmwin.h"
  10. #include "viewer.h"
  11. #include <windows.h>
  12. #include <string.h>
  13. #include "d3drm.h"
  14.  
  15. int ChooseNewColor(HWND win, D3DCOLOR* current)
  16. {
  17.     CHOOSECOLOR cc;
  18.     COLORREF clr;
  19.     COLORREF aclrCust[16];
  20.     int i;
  21.  
  22.     for (i = 0; i < 16; i++)
  23.         aclrCust[i] = RGB(255, 255, 255);
  24.  
  25.     clr =
  26.         RGB
  27.         (   (int) (255 * D3DRMColorGetRed(*current)),
  28.             (int) (255 * D3DRMColorGetGreen(*current)),
  29.             (int) (255 * D3DRMColorGetBlue(*current))
  30.         );
  31.  
  32.     memset(&cc, 0, sizeof(CHOOSECOLOR));
  33.     cc.lStructSize = sizeof(CHOOSECOLOR);
  34.     cc.hwndOwner = win;
  35.     cc.rgbResult = clr;
  36.     cc.lpCustColors = aclrCust;
  37.     cc.Flags = CC_RGBINIT|CC_FULLOPEN;
  38.  
  39.     if (ChooseColor(&cc))
  40.     {   *current =
  41.             D3DRMCreateColorRGB
  42.             (   D3DVAL(GetRValue(cc.rgbResult) / D3DVAL(255.0)),
  43.                 D3DVAL(GetGValue(cc.rgbResult) / D3DVAL(255.0)),
  44.                 D3DVAL(GetBValue(cc.rgbResult) / D3DVAL(255.0))
  45.             );
  46.         return TRUE;
  47.     }
  48.     else return FALSE;
  49. }
  50.