Gets the color at the specified position.
#include "Ltwrappr.h"
L_INT LRasterPaint::PickColor(UserDC, nX, nY, pcrDestColor)
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.
X -coordinate of the position from which to get the color.
Y -coordinate of the position from which to get the color.
Pointer to a COLORREF value to be updated with the color at the specified position.
| Value | Meaning |
|---|---|
| SUCCESS | The function was successful. |
| < 1 | An error occurred. Refer to Return Codes |
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.
L_INT LRasterPaint_PickColorExample( CWnd* pWnd, LBitmapBase* pLBitmap, L_INT nX, L_INT nY, COLORREF *pcrDestColor ){L_INT nRet;LRasterPaint rstp;CDC* pDC = pWnd->GetDC() ;HPALETTE hPalette = NULL;RECT rcSrc, rcDest ;L_TCHAR buffer [ 80 ] ;/* Initiate the Paint toolkit */nRet = rstp.Initialize ();if(nRet != SUCCESS)return nRet;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 */nRet = rstp.SetDCExtents ( &rcDest ) ;if(nRet != SUCCESS)return nRet;/* Get the color value */nRet = rstp.PickColor ( pDC->m_hDC, nX, nY, pcrDestColor ) ;if(nRet != SUCCESS)return nRet;/* 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 */nRet = rstp.Free ( ) ;if(nRet != SUCCESS)return nRet;return SUCCESS ;}