Beispiel #1
0
static HPALETTE GetSystemPalette(HDC hdc)
{
   static HPALETTE hPal = 0;	// handle to a palette
   HANDLE hLogPal;				// handle to a logical palette
   LOGPALETTE *pLogPal;			// pointer to a logical palette
   int nColors;					// number of colors

   // Find out how many palette entries we want.
   nColors = PalEntriesOnDevice(hdc);   

   // Allocate room for the palette and lock it.
   hLogPal = GlobalAlloc(GHND, sizeof(LOGPALETTE) + nColors * sizeof(PALETTEENTRY));

   // if we didn't get a logical palette, return NULL
   if (!hLogPal) return NULL;

   // get a pointer to the logical palette
   pLogPal = (LPLOGPALETTE)GlobalLock(hLogPal);

   // set some important fields
   pLogPal->palVersion = PALVERSION;
   pLogPal->palNumEntries = nColors;

   //Copy the current system palette into our logical palette */
   GetSystemPaletteEntries(hdc, 0, nColors, (LPPALETTEENTRY)(pLogPal->palPalEntry));

   // Go ahead and create the palette.  Once it's created,
   hPal = CreatePalette(pLogPal);

   // clean up
   GlobalUnlock(hLogPal);
   GlobalFree(hLogPal);

   return hPal;
}
Beispiel #2
0
HPALETTE GetSystemPalette(void)
{
    HDC hDC;                // handle to a DC
    static HPALETTE hPal = NULL;   // handle to a palette
    HANDLE hLogPal;         // handle to a logical palette
    LPLOGPALETTE lpLogPal;  // pointer to a logical palette
    int nColors;            // number of colors

    // Find out how many palette entries we want.

    hDC = GetDC(NULL);

    if (!hDC)
        return NULL;

    nColors = PalEntriesOnDevice(hDC);   // Number of palette entries

    // Allocate room for the palette and lock it.

    hLogPal = GlobalAlloc(GHND, sizeof(LOGPALETTE) + nColors *
            sizeof(PALETTEENTRY));

    // if we didn't get a logical palette, return NULL

    if (!hLogPal)
        return NULL;

    // get a pointer to the logical palette

    lpLogPal = (LPLOGPALETTE)GlobalLock(hLogPal);

    // set some important fields

    lpLogPal->palVersion = PALVERSION;
    lpLogPal->palNumEntries = nColors;

    // Copy the current system palette into our logical palette

    GetSystemPaletteEntries(hDC, 0, nColors,
            (LPPALETTEENTRY)(lpLogPal->palPalEntry));

    // Go ahead and create the palette.  Once it's created,
    // we no longer need the LOGPALETTE, so free it.    

    hPal = CreatePalette(lpLogPal);

    // clean up

    GlobalUnlock(hLogPal);
    GlobalFree(hLogPal);
    ReleaseDC(NULL, hDC);

    return hPal;
}
Beispiel #3
0
HPALETTE GetSystemPalette(void)
{
   HDC hDC;                // handle to a DC
   HPALETTE hPal = NULL;   // handle to a palette
   HANDLE hLogPal;         // handle to a logical palette
   LPLOGPALETTE lpLogPal;  // pointer to a logical palette
   int i, nColors;         // loop index, number of colors

   /* Find out how many palette entries we want. */

   hDC = GetDC(NULL);
   if (!hDC)
      return NULL;
   nColors = PalEntriesOnDevice(hDC);
   ReleaseDC(NULL, hDC);

   /* Allocate room for the palette and lock it. */
   hLogPal = GlobalAlloc(GHND, sizeof(LOGPALETTE) + nColors * sizeof(
                         PALETTEENTRY));

   /* if we didn't get a logical palette, return NULL */
   if (!hLogPal)
      return NULL;

   /* get a pointer to the logical palette */
   lpLogPal = (LPLOGPALETTE)GlobalLock(hLogPal);

   /* set some important fields */
   lpLogPal->palVersion = PALVERSION;
   lpLogPal->palNumEntries = nColors;
   for (i = 0; i < nColors; i++)
   {
      lpLogPal->palPalEntry[i].peBlue = 0;
      *((LPWORD)(&lpLogPal->palPalEntry[i].peRed)) = i;
      lpLogPal->palPalEntry[i].peFlags = PC_EXPLICIT;
   }

   /*  Go ahead and create the palette.  Once it's created,
    *  we no longer need the LOGPALETTE, so free it.
    */
   hPal = CreatePalette(lpLogPal);

   /* clean up */
   GlobalUnlock(hLogPal);
   GlobalFree(hLogPal);
   return hPal;
}