LRasterPaint::PickColor

#include "Ltwrappr.h"

L_INT LRasterPaint::PickColor(UserDC, nX, nY, pcrDestColor)

HDC UserDC;

/* handle to the device context */

L_INT nX;

/* x-coordinate */

L_INT nY;

/* y-coordinate */

COLORREF * pcrDestColor;

/* pointer to a color */

Gets the color at the specified position.

Parameter

Description

UserDC

Handle to a device context, such as a screen, to use as a display surface. This parameter can also be NULL. . The mapping mode of the device context must be MM_TEXT.

nX

X -coordinate of the position from which to get the color.

nY

Y -coordinate of the position from which to get the color.

pcrDestColor

Pointer to a COLORREF value to be updated with the color at the specified position.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes

Comments

If the user has set a bitmap in the toolkit, using the function LRasterPaint::SetMetrics, then the toolkit will get the color at the specified position of the bitmap. Otherwise, the toolkit will get the color from the specified position of the specified device context.

Required DLLs and Libraries

LTPNT

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application

See Also

Functions:

LRasterPaint::SetTransformation, LRasterPaint::SetDCExtents, LRasterPaint::GetTransformation, LRasterPaint::GetDCExtents, LRasterPaint::FillBorder, LRasterPaint::FillColorReplace, LRasterPaint::FillSurface, Class Members

Topics:

Filling an Area

Example

L_INT PickColorTest ( CWnd* pWnd, LBitmapBase*  pLBitmap, L_INT nX, L_INT nY, COLORREF *pcrDestColor ) 
{
   LRasterPaint rstp;
   CDC* pDC = pWnd->GetDC() ;
   HPALETTE hPalette ; 
   RECT rcSrc, rcDest ;
   L_TCHAR buffer [ 80 ] ;

   /* Initiate the Paint toolkit */
  if ( SUCCESS != rstp.Initialize (  ) )
   {
      return FAILURE ; 
   }

   pLBitmap->Paint()->SetDC( pDC->m_hDC );

   /* Create restriction palette (if needed) */
   pLBitmap->SetPalette( pLBitmap->CreatePaintPalette( pDC->m_hDC ) );

   /* Set the bitmap painting coordinates  */
   SetRect ( &rcSrc, 0, 0, pLBitmap->GetWidth( ), pLBitmap->GetHeight( ) ) ;

   CopyRect ( &rcDest, &rcSrc ) ;

   /* paint the bitmap */
   pLBitmap->Paint()->SetDC( pDC->m_hDC );
   pLBitmap->SetSrcRect( &rcSrc );
   pLBitmap->SetDstRect( &rcDest );
   pLBitmap->Paint()->PaintDC();

   /* Set the extents of the DC that we are going to pick the color from */
   rstp.SetDCExtents ( &rcDest ) ;

   /* Get the color value */
   rstp.PickColor ( pDC->m_hDC, nX, nY, pcrDestColor ) ;

   /* Display the results */
   wsprintf ( buffer, 
             TEXT("R:%d G:%d B:%d"), 
             GetRValue ( *pcrDestColor ),
             GetGValue ( *pcrDestColor ),
             GetBValue ( *pcrDestColor ) ) ;

   pWnd->SetWindowText ( buffer ) ;

   
   pLBitmap->Paint()->SetDC(NULL);

   /* Release the DC */
   pWnd->ReleaseDC( pDC ) ;

   /* Delete the font object */
   DeleteObject ( (HPALETTE ) hPalette ) ;

   /* Free the paint tools handle */
   rstp.Free ( ) ;

   return SUCCESS ;
}