This sample illustrates pictures in dropdown list combo boxes, using the small icons Windows provides. The first combo box shows a hierarchy with default item pictures for expandable, expanded and leaf items (SetPictures), individual item pictures (SetItemPicture), tree lines and expand/collapse buttons; the hierarchy is defined using SetItemLevel, Collapse and Expand, and an item is expanded or collapsed when the user clicks its expand/collapse button (SFTBOXN_LBUTTONDOWN_BUTTON and SFTBOXN_LBUTTONDBLCLK_BUTTON, GetExpandCollapseIndex, SetItemExpand). The second combo box has two columns, a picture for each item and a picture on the dropdown button (SetDropDownButtonPicture).
The source code is located at C:\Program Files (x86)\Softelvdm\SftBox DLL 6.0\Samples\C\ItemImages\ItemImages.c.
/****************************************************************************/ /* SftBox/DLL 6.0 - ComboBox Control for Windows */ /* Copyright (C) 1997, 2026 Softel vdm, Inc. All Rights Reserved. */ /****************************************************************************/ /* SftBox/DLL 6.0 sample. Guide: https://softelvdm.com/Vault/Softelvdm.com/llms/SftBox-DLL-6.0.txt, API reference: https://softelvdm.com/Vault/Softelvdm.com/llms/SftBox-DLL-6.0-reference.txt - see AGENTS.md. */ #include <windows.h> #include <shellapi.h> #include "SftBox.h" /* SftBox/DLL Header File */ #define SFTDARKMODE_IMPLEMENTATION #include "SftDarkMode.h" /* Dark mode support */ #include "resource.h" // application resources HINSTANCE g_hInst; // App Instance Handle /**********************************************************************/ /* Pictures */ /**********************************************************************/ // This sample uses the small icons Windows provides. Bitmaps, image lists, // GDI+ images and color samples can be used in the same way, see the // Sft_SetPictureXxx functions in SftPicture2.h. enum { ICON_FOLDER, ICON_FOLDEROPEN, ICON_DOCUMENT, ICON_IMAGE, ICON_AUDIO, ICON_VIDEO, ICON_DRIVE, ICON_CDROM, ICON_NETWORK, ICON_PRINTER, ICON_FIND, ICON_COUNT }; static const SHSTOCKICONID m_aIconIds[ICON_COUNT] = { SIID_FOLDER, SIID_FOLDEROPEN, SIID_DOCNOASSOC, SIID_IMAGEFILES, SIID_AUDIOFILES, SIID_VIDEOFILES, SIID_DRIVEFIXED, SIID_DRIVECD, SIID_DRIVENET, SIID_PRINTER, SIID_FIND, }; static HICON m_ahIcons[ICON_COUNT]; static void LoadIcons(void) { int i; for (i = 0 ; i < ICON_COUNT ; ++i) { SHSTOCKICONINFO sii; memset(&sii, 0, sizeof(sii)); sii.cbSize = sizeof(sii); if (SUCCEEDED(SHGetStockIconInfo(m_aIconIds[i], SHGSI_ICON | SHGSI_SMALLICON, &sii))) m_ahIcons[i] = sii.hIcon; } } static void FreeIcons(void) { // Pictures are owned by the application and can be deleted // once the controls using them have been destroyed. int i; for (i = 0 ; i < ICON_COUNT ; ++i) { if (m_ahIcons[i]) DestroyIcon(m_ahIcons[i]); m_ahIcons[i] = NULL; } } /**********************************************************************/ /* Hierarchical Combo Box */ /**********************************************************************/ typedef struct tagFolderItem { int level; // 0 is the top level LPCTSTR lpszText; int icon; // -1 for the default item picture } FOLDERITEM; static const FOLDERITEM m_aFolders[] = { { 0, TEXT("Documents"), -1 }, { 1, TEXT("Letters"), -1 }, { 2, TEXT("Welcome"), -1 }, { 2, TEXT("Reminder"), -1 }, { 1, TEXT("Reports"), -1 }, { 2, TEXT("Budget"), -1 }, { 2, TEXT("Forecast"), -1 }, { 0, TEXT("Pictures"), -1 }, { 1, TEXT("Beach"), ICON_IMAGE }, { 1, TEXT("Mountains"), ICON_IMAGE }, { 0, TEXT("Music"), -1 }, { 1, TEXT("Favorites"), -1 }, { 2, TEXT("Morning"), ICON_AUDIO }, { 2, TEXT("Evening"), ICON_AUDIO }, { 0, TEXT("Videos"), -1 }, { 1, TEXT("Birthday"), ICON_VIDEO }, }; #define FOLDER_COUNT (sizeof(m_aFolders) / sizeof(m_aFolders[0])) static void InitFolders(HWND hwndBox) { SFT_PICTURE aThreeItemPictures[3]; int i; // The default item pictures: an item with dependents, the same item // when expanded and an item without dependents. All item pictures // of a control are the same size. Sft_InitPicture(&aThreeItemPictures[0]); Sft_InitPicture(&aThreeItemPictures[1]); Sft_InitPicture(&aThreeItemPictures[2]); Sft_SetPictureIcon(&aThreeItemPictures[0], m_ahIcons[ICON_FOLDER]); /* Expandable picture */ Sft_SetPictureIcon(&aThreeItemPictures[1], m_ahIcons[ICON_FOLDEROPEN]);/* Expanded picture */ Sft_SetPictureIcon(&aThreeItemPictures[2], m_ahIcons[ICON_DOCUMENT]); /* Leaf picture */ SftBox_SetPictures(hwndBox, aThreeItemPictures); SftBox_SetTreeLineStyle(hwndBox, SFTBOX_TREELINE_AUTOMATIC);// Dotted or invisible tree lines, following the Windows theme SftBox_SetShowButtons(hwndBox, TRUE); // Expand/collapse buttons (level 1..n) SftBox_SetShowButton0(hwndBox, TRUE); // Expand/collapse buttons (level 0) SftBox_SetButtons(hwndBox, SFTBOX_BUTTON_AUTOMATIC);// Button style follows the Windows theme SftBox_SetDroppedHeight(hwndBox, 12); // Show up to 12 items SftBox_SetDarkMode(hwndBox, SFTBOX_DARKMODE_AUTO); // The level of an item defines the hierarchy: an item is a // dependent of the closest preceding item with a lower level. for (i = 0 ; i < FOLDER_COUNT ; ++i) { LONG index = SftBox_AddString(hwndBox, m_aFolders[i].lpszText); SftBox_SetItemLevel(hwndBox, index, m_aFolders[i].level); if (m_aFolders[i].icon >= 0) { SFT_PICTURE Picture; Sft_InitPicture(&Picture); Sft_SetPictureIcon(&Picture, m_ahIcons[m_aFolders[i].icon]); SftBox_SetItemPicture(hwndBox, index, &Picture);// Override the default item picture } } // Collapse the top level items for (i = 0 ; i < FOLDER_COUNT ; ++i) { if (m_aFolders[i].level == 0) SftBox_Collapse(hwndBox, i, TRUE); } SftBox_Expand(hwndBox, 0, TRUE, FALSE); // Show the dependents of the first item SftBox_RecalcHorizontalExtent(hwndBox, 0); SftBox_SetCurSel(hwndBox, 0); } /**********************************************************************/ /* Item Pictures and a Button Picture */ /**********************************************************************/ typedef struct tagDevice { LPCTSTR lpszText; LPCTSTR lpszType; int icon; } DEVICE; static const DEVICE m_aDevices[] = { { TEXT("System"), TEXT("Local disk"), ICON_DRIVE }, { TEXT("Data"), TEXT("Local disk"), ICON_DRIVE }, { TEXT("Backup"), TEXT("CD drive"), ICON_CDROM }, { TEXT("Projects"), TEXT("Network drive"), ICON_NETWORK }, { TEXT("Archive"), TEXT("Network drive"), ICON_NETWORK }, { TEXT("Office"), TEXT("Printer"), ICON_PRINTER }, }; #define DEVICE_COUNT (sizeof(m_aDevices) / sizeof(m_aDevices[0])) static void InitColumn(LPSFTBOX_COLUMN lpCol, int position, int width, LPCTSTR lpszTitle) { memset(lpCol, 0, sizeof(SFTBOX_COLUMN)); lpCol->width = width; lpCol->style = ES_LEFT; lpCol->styleTitle = ES_LEFT | SFTBOX_HEADER_UP; lpCol->lpszTitle = (LPTSTR) lpszTitle; lpCol->colorBg = lpCol->colorFg = lpCol->colorBgSel = lpCol->colorFgSel = SFTBOX_NOCOLOR; lpCol->colorBgEnd = lpCol->colorBgSelEnd = SFTBOX_NOCOLOR; lpCol->colorProgress = lpCol->colorProgressEnd = SFTBOX_NOCOLOR; lpCol->realPos = lpCol->dispPos = position; } static void InitDevices(HWND hwndBox) { SFTBOX_COLUMN aCols[2]; SFT_PICTURE Picture; int i; InitColumn(&aCols[0], 0, 90, TEXT("Name")); InitColumn(&aCols[1], 1, 100, TEXT("Type")); SftBox_SetColumns(hwndBox, 2, aCols); SftBox_SetShowHeaderDropDown(hwndBox, TRUE);// Column titles in the dropdown only SftBox_SetDropDownOptimalWidth(hwndBox, TRUE);// The dropdown is as wide as its columns SftBox_SetDarkMode(hwndBox, SFTBOX_DARKMODE_AUTO); // A picture instead of the arrow on the dropdown button Sft_InitPicture(&Picture); Sft_SetPictureIcon(&Picture, m_ahIcons[ICON_FIND]); SftBox_SetDropDownButtonPicture(hwndBox, &Picture); // Register the item picture size. Only one picture needs to be // registered, even if several are used. Sft_InitPicture(&Picture); Sft_SetPictureIcon(&Picture, m_ahIcons[ICON_DRIVE]); SftBox_SetItemPicture(hwndBox, -1, &Picture); for (i = 0 ; i < DEVICE_COUNT ; ++i) { LONG index = SftBox_AddString(hwndBox, m_aDevices[i].lpszText); SftBox_SetText(hwndBox, index, 1, m_aDevices[i].lpszType); Sft_InitPicture(&Picture); Sft_SetPictureIcon(&Picture, m_ahIcons[m_aDevices[i].icon]); SftBox_SetItemPicture(hwndBox, index, &Picture); } SftBox_RecalcHorizontalExtent(hwndBox, 0); SftBox_SetCurSel(hwndBox, 0); } /**********************************************************************/ /* Expanding and Collapsing */ /**********************************************************************/ // The combo box reports a click on an expand/collapse button, the // application expands or collapses the item. static void ExpandCollapse(HWND hwndBox) { int index = SftBox_GetExpandCollapseIndex(hwndBox); if (index >= 0) SftBox_SetItemExpand(hwndBox, index, !SftBox_GetItemExpand(hwndBox, index), FALSE); } /**********************************************************************/ /* Dialog Proc */ /**********************************************************************/ INT_PTR CALLBACK MainDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_APP))); InitFolders(GetDlgItem(hwndDlg, IDC_FOLDERS)); InitDevices(GetDlgItem(hwndDlg, IDC_DEVICES)); SftDarkMode_ApplyToDialog(hwndDlg); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: EndDialog(hwndDlg, 0); return TRUE; case IDC_FOLDERS: switch (HIWORD(wParam)) { case SFTBOXN_LBUTTONDOWN_BUTTON: // expand/collapse button clicked case SFTBOXN_LBUTTONDBLCLK_BUTTON: ExpandCollapse((HWND) lParam); return TRUE; } break; } break; } { INT_PTR dmResult; if (SftDarkMode_HandleDialogMessage(hwndDlg, msg, wParam, lParam, &dmResult)) return dmResult; } return FALSE; } /**********************************************************************/ /* WinMain */ /**********************************************************************/ int PASCAL WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpszCmdLine, int cmdShow) { g_hInst = hinst; SftDarkMode_Init(); /* Dark mode support */ SftBox_RegisterApp(hinst); /* Register with SftBox/DLL */ LoadIcons(); DialogBox(g_hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, MainDialogProc); FreeIcons(); SftBox_UnregisterApp(hinst); /* Unregister from SftBox/DLL */ return 0; }