#include <Windows.h>
#include <CommDlg.h>
#include <WinTen.h>
#include <ClipApi.h>

//----------------------------------------------------------------------------//

CLIPPER CHOOSECOLO() // R( nDefaultRGBColor, nFlags ) --> nRGBColor
{
   CHOOSECOLOR ccTemp;
   COLORREF crTemp[ 16 ];

   // Gray tones for "Custom Colors"

   DWORD dwCustClrs[ 16 ];

   dwCustClrs[  0 ] = RGB( 255, 255, 255 );
   dwCustClrs[  1 ] = RGB( 239, 239, 239 );
   dwCustClrs[  2 ] = RGB( 223, 223, 223 );
   dwCustClrs[  3 ] = RGB( 207, 207, 207 );
   dwCustClrs[  4 ] = RGB( 191, 191, 191 );
   dwCustClrs[  5 ] = RGB( 175, 175, 175 );
   dwCustClrs[  6 ] = RGB( 159, 159, 159 );
   dwCustClrs[  7 ] = RGB( 143, 143, 143 );
   dwCustClrs[  8 ] = RGB( 127, 127, 127 );
   dwCustClrs[  9 ] = RGB( 111, 111, 111 );
   dwCustClrs[ 10 ] = RGB(  95,  95,  95 );
   dwCustClrs[ 11 ] = RGB(  79,  79,  79 );
   dwCustClrs[ 12 ] = RGB(  63,  63,  63 );
   dwCustClrs[ 13 ] = RGB(  47,  47,  47 );
   dwCustClrs[ 14 ] = RGB(  31,  31,  31 );
   dwCustClrs[ 15 ] = RGB(  15,  15,  15 );

   _bset( (LPBYTE) &ccTemp, 0, sizeof( CHOOSECOLOR ) );

   ccTemp.lStructSize  = sizeof( CHOOSECOLOR );
   ccTemp.hwndOwner    = GetActiveWindow();
   ccTemp.lpCustColors = (LPDWORD) dwCustClrs;

   ccTemp.rgbResult = PCOUNT() && ISNUM( 1 ) ?  _parnl( 1 ) : RGB( 0, 0, 0 );
   ccTemp.Flags     = PCOUNT() > 1 && ISNUM( 2 ) ? _parni( 2 ) :
                                      CC_RGBINIT  | CC_FULLOPEN;

   if( ChooseColor( &ccTemp ) )
      _retnl( ccTemp.rgbResult );
   else
      _retnl( _parnl( 1 ) );
}

//----------------------------------------------------------------------------//
