Hide

SftBox/OCX 5.0 - Combo Box Control

Display
Print

Features Sample (C++)

This sample illustrates a simple combo box with fonts, bitmaps.

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

BOOL CFeaturesDlg::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

    HRESULT hr;
    ISftBoxPtr vBox1 = m_Box1.GetControlUnknown();

    // load pictures
    PICTDESC PictDesc;
    PictDesc.cbSizeofstruct = sizeof(PICTDESC);
    PictDesc.picType = PICTYPE_BITMAP;
    PictDesc.bmp.hbitmap = LoadBitmap(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDB_PICTURE));
    PictDesc.bmp.hpal = NULL;
    hr = OleCreatePictureIndirect(&PictDesc, IID_IPictureDisp, TRUE, (void**)&m_pIPictureDispPicture);
    ASSERT(SUCCEEDED(hr));
    PictDesc.bmp.hbitmap = LoadBitmap(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDB_PIN));
    hr = OleCreatePictureIndirect(&PictDesc, IID_IPictureDisp, TRUE, (void**)&m_pIPictureDispPin);
    ASSERT(SUCCEEDED(hr));
    PictDesc.bmp.hbitmap = LoadBitmap(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDB_SPECIAL));
    hr = OleCreatePictureIndirect(&PictDesc, IID_IPictureDisp, TRUE, (void**)&m_pIPictureDispSpecial);
    ASSERT(SUCCEEDED(hr));

    vBox1->putref_Font(NULL); // use the form's default font
    vBox1->Edit->putref_Font(NULL);
    vBox1->RowHeaders->putref_Font(NULL);
    // make a bold font
    IFontPtr pFont = vBox1->GetFont();
    IFontPtr pFontNew;
    hr = pFont->Clone(&pFontNew);
    ASSERT(SUCCEEDED(hr));
    hr = pFontNew->QueryInterface(IID_IFontDisp, (void**) &m_pBoldFont);
    ASSERT(SUCCEEDED(hr));
    pFontNew->put_Bold(TRUE);
    // .. and an italic font
    hr = pFont->Clone(&pFontNew);
    ASSERT(SUCCEEDED(hr));
    hr = pFontNew->QueryInterface(IID_IFontDisp, (void**) &m_pItalicFont);
    ASSERT(SUCCEEDED(hr));
    pFontNew->put_Italic(TRUE);


    vBox1->BulkUpdate = VARIANT_TRUE;
    for (long index = 0 ; index < 30 ; ++index) {
        if (index == 4) {
            CString s0, s2;
            s0.Format("Item %ld", index);
            s2.Format("Cell %ld,2", index);
            AddOneItem(s0, "This cell text is very long", s2);
        } else if (index == 7) {
            CString s0, s1;
            s0.Format("Item %ld", index);
            s1.Format("Cell %ld,1", index);
            AddOneItem(s0, s1, "This cell text is also very long");
        } else {
            CString s0, s1, s2;
            s0.Format("Item %ld", index);
            s1.Format("Cell %ld,1", index);
            s2.Format("Cell %ld,2", index);
            AddOneItem(s0, s1, s2);
        }
    }
    vBox1->BulkUpdate = VARIANT_FALSE;

    CRect rect;
    m_Box1.GetClientRect(&rect);
    vBox1->Column[0]->WidthPix = rect.Width() / 4;
    vBox1->Column[1]->WidthPix = rect.Width() / 4;
    vBox1->RowHeaders->MakeOptimal(0);
    vBox1->Column[2]->MakeOptimal(0);
    vBox1->Items->RecalcHorizontalExtent(0);

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

long CFeaturesDlg::AddOneItem(LPCTSTR lpszCell0, LPCTSTR lpszCell1, LPCTSTR lpszCell2)
{
    ISftBoxPtr vBox1 = m_Box1.GetControlUnknown();

    long index = vBox1->Items->Add(lpszCell0);
    vBox1->Cell[index][1]->Text = lpszCell1;

    if ((index % 4) == 0) {
        vBox1->Cell[index][1]->Image->putref_Picture(m_pIPictureDispSpecial);
        if ((index % 8) == 0)
            vBox1->Cell[index][1]->ImageHAlign = halignSftBoxRight;
    }
    vBox1->Cell[index][2]->Text = lpszCell2;
    if ((index % 5) == 0) {
        vBox1->Cell[index][2]->Image->putref_Picture(m_pIPictureDispPin);
        if ((index % 10) != 0)
            vBox1->Cell[index][2]->ImageHAlign = halignSftBoxRight;
    }
    if ((index % 3) == 0) {
        vBox1->Item[index]->RowHeader->Image->putref_Picture(m_pIPictureDispPicture);
        if ((index % 6) != 0)
            vBox1->Item[index]->RowHeader->ImageHAlign = halignSftBoxRight;
    }
    if ((index % 6) == 0)
        vBox1->Cell[index][0]->putref_Font(m_pBoldFont);
    if ((index % 7) == 0)
        vBox1->Cell[index][0]->putref_Font(m_pItalicFont);

    return index;
}

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