19.6.1 Responding to the WM_QUERYNEWPALETTE Message

Windows sends the WM_QUERYNEWPALETTE message to the window that is about to become active. When a window receives this message, the application that owns the window should realize its logical palette, invalidate the contents of the window's client area, and then return TRUE to inform Windows that it has changed the system palette.

ShowDIB responds to the WM_QUERYNEWPALETTE message as follows:

case WM_QUERYNEWPALETTE:

        /* If palette realization causes a palette change, redraw. */

        if (fLegitDraw) {
            hDC = GetDC(hWnd);
            hOldPal = SelectPalette(hDC, hpalCurrent, 0);

            i = RealizePalette(hDC);

            SelectPalette(hDC, hOldPal, 0);
            ReleaseDC(hWnd, hDC);

            if (i) {
                InvalidateRect(hWnd, (RECT FAR*) NULL, 1);
                UpdateCount = 0;
                return 1;
            } else
                return FALSE;
        }
        else
            return FALSE;
        break;