SftTree/DLL 7.5 - Tree Control
SftBox/OCX 5.0 - Combo Box Control
SftButton/OCX 3.0 - Button Control
SftMask/OCX 7.0 - Masked Edit Control
SftTabs/OCX 6.5 - Tab Control (VB6 only)
SftTree/OCX 7.5 - Tree Control
SftPrintPreview/DLL 2.0 - Print Preview Control (discontinued)
SftTree/DLL 7.5 - Tree Control
SftBox/OCX 5.0 - Combo Box Control
SftButton/OCX 3.0 - Button Control
SftDirectory 3.5 - File/Folder Control (discontinued)
SftMask/OCX 7.0 - Masked Edit Control
SftOptions 1.0 - Registry/INI Control (discontinued)
SftPrintPreview/OCX 1.0 - Print Preview Control (discontinued)
SftTabs/OCX 6.5 - Tab Control (VB6 only)
SftTree/OCX 7.5 - Tree Control
SftTabs/NET 6.0 - Tab Control (discontinued)
SftTree/NET 2.0 - Tree Control
This sample illustrates images, checkboxes, radiobuttons, more.
The source code is located at C:\Program Files (x86)\Softelvdm\SftBox OCX 5.0\Samples\VC++\Pictures\PicturesDlg.cpp or C:\Program Files\Softelvdm\SftBox OCX 5.0\Samples\VC++\Pictures\PicturesDlg.cpp (on 32-bit Windows versions).
struct tagColorEntry { LPCTSTR lpszName; COLORREF color; } aPropListColors[] = { { TEXT("Black"), RGB( 0, 0, 0), }, { TEXT("Blue"), RGB( 0, 0,255), }, { TEXT("Cyan"), RGB( 0,255,255), }, { TEXT("Green"), RGB( 0,255, 0), }, { TEXT("Magenta"), RGB(255, 0,255), }, { TEXT("Red"), RGB(255, 0, 0), }, { TEXT("White"), RGB(255,255,255), }, { TEXT("Yellow"), RGB(255,255, 0), }, { TEXT("Dk Blue"), RGB( 0, 0,128), }, { TEXT("Dk Cyan"), RGB( 0,128,128), }, { TEXT("Dk Green"), RGB( 0,128, 0), }, { TEXT("Dk Magenta"), RGB(128, 0,128), }, { TEXT("Dk Red"), RGB(128, 0, 0), }, { TEXT("Dk Yellow"), RGB(128,128, 0), }, { TEXT("Dk Gray"), RGB(128,128,128), }, { TEXT("Lt Gray"), RGB(192,192,192), }, { TEXT("3DDKSHADOW - Dark shadow for 3D elements"), 0x80000000L | COLOR_3DDKSHADOW, }, { TEXT("3DFACE - Face color for 3D elements"), 0x80000000L | COLOR_3DFACE, }, { TEXT("3DHILIGHT - Edges facing the light source"), 0x80000000L | COLOR_3DHILIGHT, }, { TEXT("3DLIGHT - Edges facing the light source"), 0x80000000L | COLOR_3DLIGHT, }, { TEXT("3DSHADOW - Edges facing away from the light source"), 0x80000000L | COLOR_3DSHADOW, }, { TEXT("INFOBK - Background color for tooltip controls"), 0x80000000L | COLOR_INFOBK, }, { TEXT("INFOTEXT - Text color for tooltip controls"), 0x80000000L | COLOR_INFOTEXT, }, { TEXT("MENUTEXT - Text in menus"), 0x80000000L | COLOR_MENUTEXT, }, { TEXT("ACTIVEBORDER - Active window border"), 0x80000000L | COLOR_ACTIVEBORDER, }, { TEXT("ACTIVECAPTION - Active window caption"), 0x80000000L | COLOR_ACTIVECAPTION, }, { TEXT("APPWORKSPACE - Background color MDI applications"), 0x80000000L | COLOR_APPWORKSPACE, }, { TEXT("BACKGROUND - Desktop"), 0x80000000L | COLOR_BACKGROUND, }, { TEXT("BTNFACE - Face shading on push buttons"), 0x80000000L | COLOR_BTNFACE, }, { TEXT("BTNHILIGHT - Highlight color for buttons"), 0x80000000L | COLOR_BTNHIGHLIGHT, }, { TEXT("BTNSHADOW - Edge shading on push buttons"), 0x80000000L | COLOR_BTNSHADOW, }, { TEXT("BTNTEXT - Text on push buttons"), 0x80000000L | COLOR_BTNTEXT, }, { TEXT("CAPTIONTEXT - Text in caption"), 0x80000000L | COLOR_CAPTIONTEXT, }, { TEXT("GRAYTEXT - Grayed (disabled) text"), 0x80000000L | COLOR_GRAYTEXT, }, { TEXT("HIGHLIGHT - Selected Item(s)"), 0x80000000L | COLOR_HIGHLIGHT, }, { TEXT("HIGHLIGHTTEXT - Text of selected item(s)"), 0x80000000L | COLOR_HIGHLIGHTTEXT, }, { TEXT("INACTIVEBORDER - Inactive window border"), 0x80000000L | COLOR_INACTIVEBORDER, }, { TEXT("INACTIVECAPTION - Inactive window caption"), 0x80000000L | COLOR_INACTIVECAPTION, }, { TEXT("INACTIVECAPTIONTEXT - Inactive caption text color"), 0x80000000L | COLOR_INACTIVECAPTIONTEXT, }, { TEXT("MENU - Menu background"), 0x80000000L | COLOR_MENU, }, { TEXT("SCROLLBAR - Scroll bar gray area"), 0x80000000L | COLOR_SCROLLBAR, }, { TEXT("WINDOW - Window background"), 0x80000000L | COLOR_WINDOW, }, { TEXT("WINDOWFRAME - Window frame"), 0x80000000L | COLOR_WINDOWFRAME, }, { TEXT("WINDOWTEXT - Text in windows"), 0x80000000L | COLOR_WINDOWTEXT, }, { NULL, 0 }, }; BOOL CPicturesDlg::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 m_vBox = m_Box.GetControlUnknown(); ASSERT(m_vBox != NULL); long ItemIndex = m_vBox->Items->Add("Supported Picture Types"); m_vBox->Cell[ItemIndex][1]->Text = _T("SftBox/OCX supports numerous image types, such as GDI+ images, bitmaps, icons, ImageLists and also offers numerous built-in images."); // add GDI+ samples ItemIndex = m_vBox->Items->Add(_T("GDI+ Images")); m_vBox->Item[ItemIndex]->Level = 1; m_vBox->Cell[ItemIndex][1]->Text = _T("All GDI+ images are supported, like GIF, JPEG, Exif, PNG, TIFF and device-independent bitmaps (up to 64bpp) with semi-transparent and translucent areas."); long i = m_vBox->Items->Add(_T("PNG Sample with alpha-channel for translucent edges")); m_vBox->Item[i]->Level = 2; UpdateImage(i, IDR_PNG_WARNING, halignSftBoxRight); i = m_vBox->Items->Add(_T("Another PNG Sample with alpha-channel for translucent edges")); m_vBox->Item[i]->Level = 2; UpdateImage(i, IDR_PNG_WORLD, halignSftBoxRight); // add bitmap samples ItemIndex = m_vBox->Items->Add(_T("Bitmaps")); m_vBox->Item[ItemIndex]->Level = 1; m_vBox->Cell[ItemIndex][1]->Text = _T("Bitmaps can be of varying sizes and also support Bitmap Transparency, which allows the background to show through the image (in areas selected by the bitmap designer)."); i = m_vBox->Items->Add(_T("Large Bitmap")); m_vBox->Item[i]->Level = 2; UpdateBitmap(i, m_Logo, halignSftBoxRight); i = m_vBox->Items->Add(_T("Various bitmap sizes")); m_vBox->Item[i]->Level = 2; UpdateBitmap(i, m_SmallBitmap, halignSftBoxRight); // add icon samples ItemIndex = m_vBox->Items->Add(_T("Icons")); m_vBox->Item[ItemIndex]->Level = 1; m_vBox->Cell[ItemIndex][1]->Text = _T("The supported icons can be stardard size icons (32x32) or any other size supported by the operating system."); i = m_vBox->Items->Add(_T("Standard Icon (32x32)")); m_vBox->Item[i]->Level = 2; UpdateIcon(i, m_hIcon, halignSftBoxRight); i = m_vBox->Items->Add(_T("Any other size")); m_vBox->Item[i]->Level = 2; UpdateIcon(i, m_hIconSmall, halignSftBoxRight); // add imagelist samples ItemIndex = m_vBox->Items->Add(_T("ImageLists")); m_vBox->Item[ItemIndex]->Level = 1; m_vBox->Cell[ItemIndex][1]->Text = _T("Complete ImageList support simplifies bitmap handling and can avoid the limited resource availability on earlier Windows versions."); { int c, count = m_ImgList.GetImageCount(); for (c = 0 ; c < count ; ++c) { TCHAR szBuffer[80]; int i; wsprintf(szBuffer, _T("Image %d"), c); i = m_vBox->Items->Add(szBuffer); m_vBox->Item[i]->Level = 2; UpdateImageList(i, (HIMAGELIST) m_ImgList, (short) c, halignSftBoxRight); } } // add color samples ItemIndex = m_vBox->Items->Add(_T("Color Samples")); m_vBox->Item[ItemIndex]->Level = 1; m_vBox->Cell[ItemIndex][1]->Text = _T("Using the built-in color sample image, simple color selection can easily be implemented. Color samples can display all colors available."); { struct tagColorEntry* pc = aPropListColors; for ( ; pc->lpszName ; ++pc) { i = m_vBox->Items->Add(pc->lpszName); m_vBox->Item[i]->Level = 2; UpdateColorSample(i, pc->color, halignSftBoxRight); } } // add predefined image samples ItemIndex = m_vBox->Items->Add(_T("Predefined (Built-in) Pictures")); m_vBox->Cell[ItemIndex][1]->Text = _T("Predefined images are available for commonly used items, such as check boxes, radio buttons, sort direction indicators and more..."); ItemIndex = m_vBox->Items->Add(_T("Check Boxes - Honors Windows Themes")); m_vBox->Item[ItemIndex]->Level = 1; AddBuiltinImage(_T("Enabled, Selected Check Box"), sftImageCheckboxYes, 14, 14); AddBuiltinImage(_T("Disabled, Selected Check Box"), sftImageCheckboxYesDisabled, 14, 14); AddBuiltinImage(_T("Enabled Check Box"), sftImageCheckboxNo, 14, 14); AddBuiltinImage(_T("Disabled Check Box"), sftImageCheckboxNoDisabled, 14, 14); AddBuiltinImage(_T("Enabled, Unknown Check Box"), sftImageCheckboxUnknown, 14, 14); AddBuiltinImage(_T("Disabled, Unknown Check Box"), sftImageCheckboxUnknownDisabled, 14, 14); ItemIndex = m_vBox->Items->Add(_T("Radio Buttons - Honors Windows Themes")); m_vBox->Item[ItemIndex]->Level = 1; AddBuiltinImage(_T("Enabled, Selected Radio Button"), sftImageRadioButtonYes, 14, 14); AddBuiltinImage(_T("Disabled, Selected Radio Button"), sftImageRadioButtonYesDisabled, 14, 14); AddBuiltinImage(_T("Enabled Radio Button"), sftImageRadioButtonNo, 14, 14); AddBuiltinImage(_T("Disabled Radio Button"), sftImageRadioButtonNoDisabled, 14, 14); ItemIndex = m_vBox->Items->Add(_T("Up/Down Buttons - Honors Windows Themes")); m_vBox->Item[ItemIndex]->Level = 1; AddBuiltinImage(_T("Enabled Up Button"), sftImageUp, 14, 14); AddBuiltinImage(_T("Disabled Up Button"), sftImageUpDisabled, 14, 14); AddBuiltinImage(_T("Enabled Down Button"), sftImageDown, 14, 14); AddBuiltinImage(_T("Disabled Down Button"), sftImageDownDisabled, 14, 14); ItemIndex = m_vBox->Items->Add(_T("Sort Direction Indicator")); m_vBox->Item[ItemIndex]->Level = 1; AddBuiltinImage(_T("Enabled Ascending Indicator"), sftImageSortAsc, 8, 8); AddBuiltinImage(_T("Disabled Ascending Indicator"), sftImageSortAscDisabled, 8, 8); AddBuiltinImage(_T("Enabled Descending Indicator"), sftImageSortDesc, 8, 8); AddBuiltinImage(_T("Disabled Descending Indicator"), sftImageSortDescDisabled, 8, 8); m_vBox->RowHeaders->MakeOptimal(0); // make the row headers optimal m_vBox->Column[0]->MakeOptimal(0); // make the first column optimal m_vBox->Items->RecalcHorizontalExtent(0); // update horizontal scroll bar m_vBox->Items->Selection = 0; CopyImageFromCurrentItem(); return TRUE; // return TRUE unless you set the focus to a control } void CPicturesDlg::PropagateImage(long ItemIndex, ISftPictureObjectPtr Img) { // don't use images that are too large in the other areas if (Img->ActualHeight <= 20 && Img->ActualWidth < 20) { m_vBox->Item[ItemIndex]->Image = Img; m_vBox->Item[ItemIndex]->LabelImage = Img; m_vBox->Item[ItemIndex]->RowHeader->Image = Img; } } void CPicturesDlg::UpdateBitmap(long ItemIndex, const CBitmap& bmp, SftBoxHAlignConstants Align) { ISftBoxCellPtr C = m_vBox->Cell[ItemIndex][0]; C->Image->PutBitmapHandle((OLE_HANDLE)(HBITMAP) bmp); C->ImageHAlign = Align; PropagateImage(ItemIndex, C->Image); } void CPicturesDlg::UpdateImage(long ItemIndex, int resourceID, SftBoxHAlignConstants Align) { ISftBoxCellPtr C = m_vBox->Cell[ItemIndex][0]; C->Image->raw_LoadImageFromResource((long) AfxGetApp()->m_hInstance, L"PNG", (LPWSTR)MAKEINTRESOURCE(resourceID)); C->ImageHAlign = Align; PropagateImage(ItemIndex, C->Image); } void CPicturesDlg::UpdateIcon(long ItemIndex, HICON hIcon, SftBoxHAlignConstants Align) { ISftBoxCellPtr C = m_vBox->Cell[ItemIndex][0]; C->Image->PutIconHandle((OLE_HANDLE)hIcon); C->ImageHAlign = Align; PropagateImage(ItemIndex, C->Image); } void CPicturesDlg::UpdateImageList(long ItemIndex, HIMAGELIST hImgList, short iImage, SftBoxHAlignConstants Align) { ISftBoxCellPtr C = m_vBox->Cell[ItemIndex][0]; C->Image->SetImageListH((OLE_HANDLE)hImgList, iImage); C->ImageHAlign = Align; PropagateImage(ItemIndex, C->Image); } void CPicturesDlg::UpdateColorSample(long ItemIndex, COLORREF Clr, SftBoxHAlignConstants Align) { ISftBoxCellPtr C = m_vBox->Cell[ItemIndex][0]; C->Image->SetColorSample(Clr, 0x80000000L|COLOR_WINDOWTEXT); C->Image->Width = 12; C->Image->Height = 12; C->ImageHAlign = Align; PropagateImage(ItemIndex, C->Image); } void CPicturesDlg::AddBuiltinImage(LPCTSTR lpszName, SftPictureImageConstants Appearance, long Width, long Height) { long ItemIndex = m_vBox->Items->Add(lpszName); m_vBox->Item[ItemIndex]->Level = 2; ISftBoxCellPtr C = m_vBox->Cell[ItemIndex][0]; C->Image->Appearance = Appearance; C->Image->Width = Width; C->Image->Height = Height; C->ImageHAlign = halignSftBoxRight; PropagateImage(ItemIndex, C->Image); } void CPicturesDlg::CopyImageFromCurrentItem() { long ItemIndex = m_vBox->Items->Selection; if (ItemIndex < 0) return; // don't use images that are too large in the other areas ISftPictureObjectPtr pImg = m_vBox->Cell[ItemIndex][0]->Image; if (pImg->ActualHeight <= 20 && pImg->ActualWidth <= 20) { m_vBox->RowColumnHeader->Image = pImg; m_vBox->Header[1]->Image = pImg; } else { m_vBox->RowColumnHeader->Image->Clear(); m_vBox->Header[1]->Image->Clear(); } } void CPicturesDlg::ExpandCollapseItem(long ItemIndex, short Shift) { ISftBoxItemPtr pItem; pItem = m_vBox->Item[ItemIndex]; if (pItem->Expanded != VARIANT_FALSE) pItem->Collapse(VARIANT_TRUE); else pItem->Expand(VARIANT_TRUE, (Shift & constSftBoxCtrlMask) ? VARIANT_TRUE : VARIANT_FALSE); } void CPicturesDlg::OnItemClickSftBox1(long Part, long AreaType, long ItemIndex, short ColNum, short Button, short Shift) { switch (AreaType) { case areaSftBoxColumn: if (ColNum == 0) SetSortDirection(!m_fSortDirection); break; case areaSftBoxCellGraphic: if (Part == partSftBoxDropDown) m_vBox->DropDown->Suppress(); // Make sure we don't close the drop down ToggleImage(m_vBox->Cell[ItemIndex][ColNum]->Image); break; case areaSftBoxItem: if (Part == partSftBoxDropDown) m_vBox->DropDown->Suppress(); // Make sure we don't close the drop down ToggleImage(m_vBox->Item[ItemIndex]->Image); break; case areaSftBoxLabel: if (Part == partSftBoxDropDown) m_vBox->DropDown->Suppress(); // Make sure we don't close the drop down ToggleImage(m_vBox->Item[ItemIndex]->LabelImage); break; case areaSftBoxButton: if (Part == partSftBoxDropDown) m_vBox->DropDown->Suppress(); // Make sure we don't close the drop down ExpandCollapseItem(ItemIndex, Shift); break; } } void CPicturesDlg::OnItemDblClkSftBox1(long Part, long AreaType, long ItemIndex, short ColNum, short Button, short Shift) { switch (AreaType) { case areaSftBoxColumnRes: m_vBox->Column[ColNum]->MakeOptimal(0); // Make column width optimal m_vBox->Items->RecalcHorizontalExtent(0); // Update horizontal scroll bar break; case areaSftBoxColumn: if (ColNum == 0) SetSortDirection(!m_fSortDirection); break; case areaSftBoxCellGraphic: if (Part == partSftBoxDropDown) m_vBox->DropDown->Suppress(); // Make sure we don't close the drop down ToggleImage(m_vBox->Cell[ItemIndex][ColNum]->Image); break; case areaSftBoxLabel: if (Part == partSftBoxDropDown) m_vBox->DropDown->Suppress(); // Make sure we don't close the drop down ToggleImage(m_vBox->Item[ItemIndex]->LabelImage); break; case areaSftBoxItem: if (Part == partSftBoxDropDown) m_vBox->DropDown->Suppress(); // Make sure we don't close the drop down if (m_vBox->Item[ItemIndex]->Expandable != VARIANT_FALSE) ExpandCollapseItem(ItemIndex, Shift); else ToggleImage(m_vBox->Item[ItemIndex]->Image); break; case areaSftBoxButton: case areaSftBoxCell: if (Part == partSftBoxDropDown) m_vBox->DropDown->Suppress(); // Make sure we don't close the drop down ExpandCollapseItem(ItemIndex, Shift); break; } } void CPicturesDlg::OnSelectionChangeSftBox1() { CopyImageFromCurrentItem(); } void CPicturesDlg::ShowSortDirection(BOOL fAscending) { if (fAscending) m_vBox->Header[0]->Image->Appearance = sftImageSortAsc; else m_vBox->Header[0]->Image->Appearance = sftImageSortDesc; m_fSortDirection = fAscending; } void CPicturesDlg::SetSortDirection(BOOL fNewDirection) { ShowSortDirection(fNewDirection); if (fNewDirection) m_vBox->Items->Sort(-1, 0, sortSftBoxAscending); else m_vBox->Items->Sort(-1, 0, sortSftBoxDescending); } void CPicturesDlg::ToggleImage(ISftPictureObjectPtr pImg) { SftPictureImageConstants Appearance = pImg->Appearance; switch (Appearance) { case sftImageCheckboxNo: pImg->Appearance = sftImageCheckboxYes; break; case sftImageCheckboxYes: pImg->Appearance = sftImageCheckboxNo; break; case sftImageCheckboxUnknown: pImg->Appearance = sftImageCheckboxNo; break; case sftImageCheckboxNoDisabled: pImg->Appearance = sftImageCheckboxYesDisabled; break; case sftImageCheckboxYesDisabled: pImg->Appearance = sftImageCheckboxNoDisabled; break; case sftImageCheckboxUnknownDisabled: pImg->Appearance = sftImageCheckboxNoDisabled; break; case sftImageRadioButtonNo: pImg->Appearance = sftImageRadioButtonYes; break; case sftImageRadioButtonYes: pImg->Appearance = sftImageRadioButtonNo; break; case sftImageRadioButtonNoDisabled: pImg->Appearance = sftImageRadioButtonYesDisabled; break; case sftImageRadioButtonYesDisabled: pImg->Appearance = sftImageRadioButtonNoDisabled; break; case sftImageUp: pImg->Appearance = sftImageDown; break; case sftImageUpDisabled: pImg->Appearance = sftImageDownDisabled; break; case sftImageDown: pImg->Appearance = sftImageUp; break; case sftImageDownDisabled: pImg->Appearance = sftImageUpDisabled; break; case sftImageSortAsc: pImg->Appearance = sftImageSortDesc; break; case sftImageSortAscDisabled: pImg->Appearance = sftImageSortDescDisabled; break; case sftImageSortDesc: pImg->Appearance = sftImageSortAsc; break; case sftImageSortDescDisabled: pImg->Appearance = sftImageSortAscDisabled; break; default: break; } } BEGIN_EVENTSINK_MAP(CPicturesDlg, CDialog) //{{AFX_EVENTSINK_MAP(CPicturesDlg) ON_EVENT(CPicturesDlg, IDC_SFTBOX1, 8 /* ItemClick */, OnItemClickSftBox1, VTS_I4 VTS_I4 VTS_I4 VTS_I2 VTS_I2 VTS_I2) ON_EVENT(CPicturesDlg, IDC_SFTBOX1, 9 /* ItemDblClk */, OnItemDblClkSftBox1, VTS_I4 VTS_I4 VTS_I4 VTS_I2 VTS_I2 VTS_I2) ON_EVENT(CPicturesDlg, IDC_SFTBOX1, 20 /* SelectionChange */, OnSelectionChangeSftBox1, VTS_NONE) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP()