Hide

SftBox/OCX 5.0 - Combo Box Control

Display
Print

Colors Sample (C++)

This sample illustrates using SftBox/OCX for color selection.

The source code is located at C:\Program Files (x86)\Softelvdm\SftBox OCX 5.0\Samples\VC++\Colors\ColorsDlg.cpp or C:\Program Files\Softelvdm\SftBox OCX 5.0\Samples\VC++\Colors\ColorsDlg.cpp (on 32-bit Windows versions).

void CColorsDlg::AddColor(ISftBoxPtr vCombo, BOOL fSmallSample, LPCTSTR lpszDescription, COLORREF color)
{
    long index = vCombo->Items->Add(lpszDescription);      // add a new item
    ISftBoxCellPtr OneCell = vCombo->Cell[index][0]; // get the first cell

    if (fSmallSample) {
        OneCell->Image->Height = 13;
        OneCell->Image->Width = 26;
    } else {
        OneCell->Image->Height = 13;
        OneCell->Image->Width = 13;
    }
    OneCell->Image->SetColorSample(color, RGB(0,0,0)); // set the cell's color sample
    // We'll save the color value in the cell's Data property so
    // we can use the Items.FindCellData method if needed
    OneCell->Data = color;
}

void CColorsDlg::AddColors(ISftBoxPtr vCombo, BOOL fSmallSample)
{
    AddColor(vCombo, fSmallSample, "Black", RGB(0,0,0));
    AddColor(vCombo, fSmallSample, "Blue", RGB(0,0,255));
    AddColor(vCombo, fSmallSample, "Cyan", RGB(0,255,255));
    AddColor(vCombo, fSmallSample, "Green", RGB(0,255,0));
    AddColor(vCombo, fSmallSample, "Magenta", RGB(255,0,255));
    AddColor(vCombo, fSmallSample, "Red", RGB(255,0,0));
    AddColor(vCombo, fSmallSample, "White", RGB(255,255,255));
    AddColor(vCombo, fSmallSample, "Yellow", RGB(255,255,0));
    AddColor(vCombo, fSmallSample, "Scroll bar color", COLOR_SCROLLBAR | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Desktop color", COLOR_DESKTOP | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Color of the title bar for the active window", COLOR_ACTIVECAPTION | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Color of the title bar for the inactive window", COLOR_INACTIVECAPTION | 0x80000000L);

    AddColor(vCombo, fSmallSample, "Menu background color", COLOR_MENUBAR | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Window background color", COLOR_WINDOW | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Window frame color", COLOR_WINDOWFRAME | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Color of text on menus", COLOR_MENUTEXT | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Color of text in windows", COLOR_WINDOWTEXT | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Color of text in caption, size box, and scroll arrow", COLOR_CAPTIONTEXT | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Border color of active window", COLOR_ACTIVEBORDER | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Border color of inactive window", COLOR_INACTIVEBORDER | 0x80000000L);

    AddColor(vCombo, fSmallSample, "Background color of multiple-document interface (MDI) applications", COLOR_APPWORKSPACE | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Background color of items selected in a control", COLOR_HIGHLIGHT | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Text color of items selected in a control", COLOR_HIGHLIGHTTEXT | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Color of shading on the face of command buttons", COLOR_BTNFACE | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Color of shading on the edge of command buttons", COLOR_BTNSHADOW | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Grayed (disabled) text", COLOR_GRAYTEXT | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Text color on push buttons", COLOR_BTNTEXT | 0x80000000L);

    AddColor(vCombo, fSmallSample, "Color of text in an inactive caption", COLOR_INACTIVECAPTIONTEXT | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Highlight color for 3D display elements", COLOR_3DHILIGHT | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Darkest shadow color for 3D display elements", COLOR_3DDKSHADOW | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Second lightest of the 3D colors after vb3Dhighlight", COLOR_3DLIGHT | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Color of text face", COLOR_3DFACE | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Color of text shadow", COLOR_3DSHADOW | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Color of text in ToolTips", COLOR_INFOTEXT | 0x80000000L);
    AddColor(vCombo, fSmallSample, "Background color of ToolTips", COLOR_INFOBK | 0x80000000L);
}

BOOL CColorsDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    // Initialize combo box 1
    ISftBoxPtr vCombo1 = m_Box1.GetControlUnknown();

    vCombo1->putref_Font(NULL); // use the form's default font
    AddColors(vCombo1, TRUE);
    // Select "red"
    long index;
    short column;
    vCombo1->Items->FindCellData(RGB(255,0,0), 0, -1, 0, &index, &column);
    vCombo1->Items->Selection = index;
    // make sure we get a horizontal scroll bar
    vCombo1->Items->RecalcHorizontalExtent(0);

    // Initialize combo box 2
    ISftBoxPtr vCombo2 = m_Box2.GetControlUnknown();

    vCombo2->putref_Font(NULL); // use the form's default font
    AddColors(vCombo2, FALSE);
    // Select "red"
    vCombo2->Items->FindCellData(RGB(255,0,0), 0, -1, 0, &index, &column);
    vCombo2->Items->Selection = index;
    // make sure we get a horizontal scroll bar
    vCombo2->Items->RecalcHorizontalExtent(0);

    // Initialize combo box 3
    ISftBoxPtr vCombo3 = m_Box3.GetControlUnknown();

    vCombo3->putref_Font(NULL); // use the form's default font
    vCombo3->Headers->putref_Font(NULL);
    AddColors(vCombo3, TRUE);
    // Select "red"
    vCombo3->Items->FindCellData(RGB(255,0,0), 0, -1, 0, &index, &column);
    vCombo3->Items->Selection = index;
    // make sure we get a horizontal scroll bar
    vCombo3->Items->RecalcHorizontalExtent(0);

    return TRUE;  // return TRUE  unless you set the focus to a control
}

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.