Pregunta

Recently I began to use CMFCColorButtons in my application replacing old custom controls. Now I want to restrict the colors that are selectable.

Therefore, I found the method "SetPalette". I create a CPalette like the following within the OnInitDialog method:

// CArray<COLORREF, COLORREF> arrColors is an array of COLORREFS coming
// from my helper class
if (arrColors.GetCount() > 0)
{
    LOGPALETTE* pLogPalette = (LOGPALETTE*) new BYTE[sizeof(LOGPALETTE) + 
                              (arrColors.GetCount() * sizeof(PALETTEENTRY))];
    pLogPalette->palNumEntries = arrColors.GetCount();

    for (int i = 0; i < arrColors.GetCount(); i++)
    {
        COLORREF currentColor = arrColors.GetAt(i);
        pLogPalette->palPalEntry[i].peRed = GetRValue(currentColor);
        pLogPalette->palPalEntry[i].peGreen = GetGValue(currentColor);
        pLogPalette->palPalEntry[i].peBlue = GetBValue(currentColor);
    }

    m_pPalette = new CPalette();
    m_pPalette->CreatePalette(pLogPalette);
    delete []pLogPalette;
}

Afterwards in the code, the CMFCColorButtons get created and the palette will be set (six color buttons in this dialog in total) called in the OnInitDialog as well:

void CMyColorPopUp::InitColorButton(CMFCColorButton* pColorButton, int iColor)
{
    pColorButton->SetPalette(m_pPalette);
    pColorButton->SetColor(iColor);
    pColorButton->SetColumnsNumber(8);
}

The behavior is not as expected. When I click on the button, the color palette is huge spanning over the whole display containing only one color for each entry (like 100 rows and 8 columns) ...

Maybe you can help with my ColorButton issue, I haven't found any additional help in the web. Thank you in advance!

- Chris

¿Fue útil?

Solución

Ok, I found the answer. I simply forgot to set the LOGPALETTE's system version. It's just one line of code:

pLogPalette->palVersion = 0x300;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top