エントリ番号 | 01 | 02 | 03 | 04 | ||
---|---|---|---|---|---|---|
ブラシで描いた矩形 | : 1番が黒で、それ以外は白 | | | 時 間 | ↓ | ||||
: 1番を白に変え、2番を黒にする | ||||||
: 2番を白に変え、3番を黒にする | ||||||
: 3番を白に変え、4番を黒にする |
BOOL AnimatePalette( HPALETTE hpal , UINT iStartIndex , UINT cEntries , CONST PALETTEENTRY *ppe );hpal には、論理パレットのハンドルを指定します
#include <windows.h> #define MAX_PAL 30 LRESULT CALLBACK WndProc(HWND hWnd , UINT msg , WPARAM wp , LPARAM lp) { HDC hdc; PAINTSTRUCT ps; HBRUSH hBrush; int count , x = 10; LOGPALETTE * lpPalette; PALETTEENTRY palEntry; static HPALETTE hPalette; static int black = 0 , white = MAX_PAL; switch (msg) { case WM_DESTROY: KillTimer(hWnd , 1); DeleteObject(hPalette); PostQuitMessage(0); return 0; case WM_CREATE: lpPalette = malloc(sizeof (LOGPALETTE) + MAX_PAL * sizeof (PALETTEENTRY)); lpPalette->palVersion = 0x0300; lpPalette->palNumEntries = MAX_PAL; for (count = 0 ; count < MAX_PAL ; count++) { lpPalette->palPalEntry[count].peRed = lpPalette->palPalEntry[count].peGreen = lpPalette->palPalEntry[count].peBlue = (count == 0 ? 0 : 255); lpPalette->palPalEntry[count].peFlags = PC_RESERVED; } hPalette = CreatePalette(lpPalette); free(lpPalette); SetTimer(hWnd , 1 , 100 , NULL); return 0; case WM_PAINT: hdc = BeginPaint(hWnd , &ps); SelectPalette(hdc , hPalette , FALSE); RealizePalette(hdc); for (count = 0 ; count < MAX_PAL ; count++ , x += 10) { hBrush = CreateSolidBrush(PALETTEINDEX(count)); SelectObject(hdc , hBrush); SelectObject(hdc , GetStockObject(NULL_PEN)); Rectangle(hdc , x , 10 , x + 10 , 30); SelectObject(hdc , GetStockObject(WHITE_BRUSH)); DeleteObject(hBrush); } EndPaint(hWnd ,&ps); return 0; case WM_QUERYNEWPALETTE: if (!hPalette) return FALSE; hdc = GetDC(hWnd); SelectPalette(hdc , hPalette , FALSE); RealizePalette(hdc); InvalidateRect(hWnd , NULL , TRUE); ReleaseDC(hWnd , hdc); return TRUE; case WM_TIMER: black = black == MAX_PAL ? 0 : black + 1; white = white == MAX_PAL ? 0 : white + 1; palEntry.peFlags = PC_RESERVED; palEntry.peRed = palEntry.peGreen = palEntry.peBlue = 0; AnimatePalette(hPalette , black , 1 , &palEntry); palEntry.peRed = palEntry.peGreen = palEntry.peBlue = 0xFF; AnimatePalette(hPalette , white , 1 , &palEntry); return 0; } return DefWindowProc(hWnd , msg , wp , lp); } int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR lpCmdLine , int nCmdShow) { HWND hWnd; MSG msg; WNDCLASS winc; winc.style = CS_HREDRAW | CS_VREDRAW; winc.lpfnWndProc = WndProc; winc.cbClsExtra = winc.cbWndExtra = 0; winc.hInstance = hInstance; winc.hIcon = LoadIcon(NULL , IDI_APPLICATION); winc.hCursor = LoadCursor(NULL , IDC_ARROW); winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winc.lpszMenuName = NULL; winc.lpszClassName = TEXT("KITTY"); if (!RegisterClass(&winc)) return 1; hWnd = CreateWindow( TEXT("KITTY") , TEXT("Kitty on your lap") , WS_OVERLAPPEDWINDOW | WS_VISIBLE , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , NULL , NULL , hInstance , NULL ); if (hWnd == NULL) return 1; while (GetMessage(&msg , NULL , 0 , 0 )) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
BOOL AnimatePalette( HPALETTE hpal , UINT iStartIndex , UINT cEntries , CONST PALETTEENTRY *ppe );論理パレットの指定範囲を置き換えます