test: tpalette.c File Reference

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# tpalette.c File Reference

`#include <windows.h>`
`#include <string.h>`
`#include <stdlib.h>`
`#include "..\..\inc\conapi.h"`

Go to the source code of this file.

## Defines

#define | FOREGROUND_WHITE (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)

## Functions

DWORD | main (int argc, char *argv[])

## Variables

BYTE | MyPalette [64]

## Define Documentation

#define FOREGROUND_WHITE (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)

| Definition at line 9 of file tpalette.c.

## Function Documentation

DWORD main | ( | int | argc,
|  | char * | argv[]
| ) |

Definition at line 33 of file tpalette.c.

References APIENTRY, BOOL, BYTE, CONSOLE_GRAPHICS_BUFFER, CreateConsoleScreenBuffer(), DbgPrint, dwFlags, DWORD, FALSE, LPSECURITY_ATTRIBUTES, MyPalette, NULL, SetConsolePalette(), and TRUE.

    00037 {
    00038     BOOL Success;
    00039     int i;
    00040     HPALETTE hPalette;
    00041     LOGPALETTE *Palette;
    00042     HANDLE hgo;
    00043     CONSOLE_GRAPHICS_BUFFER_INFO cgbi;
    00044
    00045     Palette = LocalAlloc(LMEM_FIXED,
    00046                     sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY));
    00047
    00048     Palette->palNumEntries = (WORD) 256;
    00049     Palette->palVersion    = 0x300;
    00050
    00051     /* Fill in the palette entries from the DIB color table and
    00052      * create a logical color palette.
    00053      */
    00054
    00055     for (i = 0; i < 256; i++) {
    00056         Palette->palPalEntry[i].peRed   = 255-i;
    00057         Palette->palPalEntry[i].peGreen = 255-i;
    00058         Palette->palPalEntry[i].peBlue  = 255-i;
    00059         Palette->palPalEntry[i].peFlags = (BYTE)0;
    00060     }
    00061
    00062     hPalette = CreatePalette(Palette);
    00063     if (hPalette==NULL) {
    00064         printf("first CreatePalette failed\n");
    00065         printf("last error is %x\n",GetLastError());
    00066     }
    00067
    00068 #if 0
    00069 call
    00070 HANDLE
    00071 APIENTRY
    00072 CreateConsoleScreenBuffer(
    00073     DWORD dwDesiredAccess,
    00074     DWORD dwShareMode,
    00075     LPSECURITY_ATTRIBUTES lpSecurityAttributes,
    00076     DWORD dwFlags,  == CONSOLE_GRAPHICS_BUFFER
    00077     PVOID lpScreenBufferData == pCONSOLE_GRAPHICS_BUFFER_INFO
    00078     );
    00079 typedef struct _CONSOLE_GRAPHICS_BUFFER_INFO {
    00080     DWORD dwBitMapInfoLength;
    00081     LPBITMAPINFO lpBitMapInfo;
    00082     DWORD dwUsage;
    00083     HANDLE hMutex;
    00084     PVOID lpBitMap;
    00085 } CONSOLE_GRAPHICS_BUFFER_INFO, *PCONSOLE_GRAPHICS_BUFFER_INFO;
    00086
    00087
    00088 #define CONSOLE_GRAPHICS_BUFFER  2
    00089 #endif
    00090     hgo = CreateConsoleScreenBuffer(MAXIMUM_ALLOWED, 0, NULL,
    00091             CONSOLE_GRAPHICS_BUFFER, &cgbi);
    00092     if (hgo == NULL) {
    00093         DbgPrint("CreateConsoleScreenBuffer failed\n");
    00094         return FALSE;
    00095     }
    00096     Success = SetConsolePalette(hgo,
    00097                                 hPalette,
    00098                                 SYSPAL_NOSTATIC
    00099                                );
    00100     if (!Success) {
    00101         printf("first SetConsolePalette failed\n");
    00102     }
    00103     printf("palette should be different\n");
    00104     Sleep(5000);
    00105     DeleteObject(hPalette);
    00106
    00107     /* Fill in the palette entries from the DIB color table and
    00108      * create a logical color palette.
    00109      */
    00110
    00111     for (i = 0; i < 16; i++) {
    00112         memcpy(&Palette->palPalEntry[i],
    00113                MyPalette,
    00114                64
    00115               );
    00116     }
    00117
    00118     hPalette = CreatePalette(Palette);
    00119     if (hPalette==NULL) {
    00120         printf("first CreatePalette failed\n");
    00121     }
    00122
    00123     Success = SetConsolePalette(hgo,
    00124                                 hPalette,
    00125                                 SYSPAL_STATIC
    00126                                );
    00127     if (!Success) {
    00128         printf("second SetConsolePalette failed\n");
    00129     }
    00130     printf("palette should be different\n");
    00131     Sleep(5000);
    00132     DeleteObject(hPalette);
    00133
    00134     printf( "TCURSOR: Exiting Test Program\n" );
    00135     return TRUE;
    00136 }

## Variable Documentation

BYTE MyPalette[64]

Initial value:

           { 0,   0,   0x80,0 ,
             0,   0x80,0,   0 ,
             0,   0,   0,   0 ,
             0,   0x80,0x80,0 ,
             0x80,0,   0,   0 ,
             0x80,0,   0x80,0 ,
             0x80,0x80,0,   0 ,
             0xC0,0xC0,0xC0,0 ,
             0x80,0x80,0x80,0 ,
             0,   0,   0xFF,0 ,
             0,   0xFF,0,   0 ,
             0,   0xFF,0xFF,0 ,
             0xFF,0,   0,   0 ,
             0xFF,0,   0xFF,0 ,
             0xFF,0xFF,0,   0 ,
             0xFF,0xFF,0xFF,0 }

Definition at line 13 of file tpalette.c.

Referenced by main().