_UNDOCUMENTED CORNER_ edited by Andrew Schulman written by Jeffrey M. Cogswell Figure 1: (a) Palette: ilPaletteHead Offs: 00 ilphPal Offs: 0C ilpUseCount Offs: 0E ilphLDevice Offs: 10 ilpFlags Offs: 12 ilphMetaList Offs: 14 Colors: peForeIndex Offs: 00 peCurIndex Offs: 02 pePrevIndex Offs: 04 peColor Offs: 06 PalGlobal: phNumEntries Offs: 00 phCurRealTime Offs: 02 phColors Offs: 04 (b) Region: rgnHead Offs: 00 rgnSize Offs: 0C rgnSCnt Offs: 0E rgnMaxScan Offs: 10 rgnBBox Offs: 12 rgnScnList Offs: 1A Scans: scnPntCnt Offs: 00 scnPntTop Offs: 02 scnPntBottom Offs: 04 scnPntsX Offs: 06 scnPtCntToo Offs: 0A Figure 2 typedef struct tagPALETTEENTRY { BYTE peRed; BYTE peGreen; BYTE peBlue; BYTE peFlags; } PALETTEENTRY; typedef struct tagLOGPALETTE WORD palVersion; WORD palNumEntries; PALETTEENTRY palPalEntry[1]; } LOGPALETTE, FAR * LPLOGPALETTE; Figure 3 (a) typedef struct tagGDIOBJHDR { HANDLE hNext; WORD wMagic; DWORD dwCount; WORD wMetaList; #ifdef DEBUG_31 WORD wSelCount; HANDLE hOwner; #endif } GDIOBJHDR, FAR *LPGDIOBJHDR; (b) #include "toolhelp.h" // ... SYSTEMHEAPINFO shi; LOCALENTRY le; shi.dwSize = sizeof(shi); SystemHeapInfo(&shi); hGDI = shi.hGDISegment; for (ok = LocalFirst(&le, hGDI); ok; ok = LocalNext(&le)) if (le.wType == LT_GDI_PALETTE) printf ("%04x\n",le.hHandle); Figure 4 //structures within global heap typedef struct tagCOLORS { WORD peForeIndex; //Apparantly used for Foreground palettes. WORD peCurIndex; //Index into system palette. This //number tells us where this particular //RGB value is mapped into the system palette. WORD pePrevIndex; //Previous index. Exact use unclear. PALETTEENTRY peColor; //RGB and flags -- see Figure 2 } COLORS; typedef struct tagPALGLOBAL{ WORD phNumEntries; //number of entries WORD phCurRealTime; //number of times realized COLORS phColors[1]; //actual RGB values } PALGLOBAL; //structure within GDI's local heap typedef struct tagNewPALETTEOBJ { GDIOBJHDR ilPaletteHead; //see Figure 3(a) HANDLE ilphPal; //handle pointing to global structure WORD ilphUseCount; //Number of times currently selected HANDLE ilphLDevice; //copied in from DC when selected WORD ilpFlags; //Used internally to RealizePalette ??? WORD ilphMetaList; //Apparantly used in metafiles } NewPALETTEOBJ; Example 1: hLocal = LocalAlloc(LPTR, sizeof(LOGPALETTE) + NUMCOLORS * sizeof(PALETTEENTRY)); LogPal = (NPLOGPALETTE) LocalLock(hLocal); Example 2: (a) case WM_PAINT: hDC = BeginPaint(hWnd, &PtStr); oldpal = SelectPalette(hdc,hpal,FALSE); mapped = RealizePalette(hDC); (b) SelectPalette(hDC, hOldPal, FALSE); EndPaint(hWnd, &PtStr); Example 3: shi.dwSize = sizeof(shi); SystemHeapInfo(&shi); GDIHeap = shi.hGDISegment; GDIHeap &= 0xfffc; GDIHeap |= 1;