Objective Grid: Setting colors for individual cells using palettes

Article ID: 479
Last updated: 25 Apr, 2018
Article ID: 479
Last updated: 25 Apr, 2018
Revision: 3
Views: 1774
Posted: 24 Jan, 2001
by Meltreger B.
Updated: 25 Apr, 2018
by Meltreger B.

Problem

 


Does Objective Grid support setting foreground and background colors for individual cells via the PALETTEINDEX or PALETTERGB macro?

 

 


Cause

 


 

 


Action

 


You have to override OnDraw() and select the palette into the device context and then call the base class version of OnDraw(). The sample code below may be adapted to your needs.

Example:

CPalette m_palette;

void CMyGridView::OnInitialUpdate(CDC* pDC)
{

// Create a palette
// Allocate a log pal and fill 
// it with the color table info
UINT nEntries = ::GetSystemPaletteEntries( pDC->GetSafeHdc(), 0, 1, NULL );

LOGPALETTE* pLogPal = (LOGPALETTE *) malloc(sizeof(LOGPALETTE) + nEntries * sizeof(PALETTEENTRY));

pLogPal->palVersion = 0x300; // Windows 3.0
pLogPal->palNumEntries = nEntries; // table size

for (UINT i=0; i < nEntries; i++)
{

pLogPal->palPalEntry[i].peRed = (BYTE) i; // index into system palette

pLogPal->palPalEntry[i].peGreen = 0; // ignored when peFlags = PC_EXPLICIT

pLogPal->palPalEntry[i].peBlue = 0;

pLogPal->palPalEntry[i].peFlags = PC_EXPLICIT;

}

m_palette.CreatePalette(pLogPal);
free (pLogPal);

}

////////////////////////////////////////////////////////////////////
// CMyGridView drawing
void CMyGridView::OnDraw(CDC* pDC)
{

pDC->SelectPalette( &m_palette, FALSE );
pDC->RealizePalette();

// Call base class version of OnDraw
CGXBrowserView::OnDraw(pDC);

}


 

This article was:   Helpful | Not helpful
Report an issue
Article ID: 479
Last updated: 25 Apr, 2018
Revision: 3
Views: 1774
Posted: 24 Jan, 2001 by Meltreger B.
Updated: 25 Apr, 2018 by Meltreger B.

Others in this category