Defines the number of columns and column attributes.
C
int WINAPI SftBox_GetColumns(HWND hwndCtl, LPSFTBOX_COLUMN *lpColArray); BOOL WINAPI SftBox_SetColumns(HWND hwndCtl, int count, LPSFTBOX_COLUMN lpCols);
C++
int CSftBox::GetColumns(LPSFTBOX_COLUMN *lpColArray) const; BOOL CSftBox::SetColumns(int count, LPSFTBOX_COLUMN lpCols);
hwndCtl
The window handle of the combo box control.
lpColArray
A pointer to an LPSFTBOX_COLUMN variable, which is set on return to point to an array of SFTBOX_COLUMN structures, one for each column defined. This pointer may be NULL, in which case only the number of columns is returned.
count
The number of columns to be defined. A SFTBOX_COLUMN structure must be defined for each column. This number may be 0, in which case a single, open-ended last column is defined (the lpCols parameter is ignored).
lpCols
A pointer to an array of SFTBOX_COLUMN structures, one for each column to be defined. This pointer may be NULL if count is 0, to define a single column.
GetColumns returns the number of columns currently defined. If lpColArray is not NULL, 0 is returned if an error occurred.
SetColumns returns TRUE if the function was successful, FALSE otherwise (for example if count is negative or, in a combo box control without a virtual data source, the number of columns is changed while the combo box contains items).
The GetColumns and SetColumns functions define the number of columns and column attributes.
The columns are defined for the entire combo box. The static portion and the dropdown portion always use the same column definitions.
The pointer returned in lpColArray points to a copy of the column definitions, an array of SFTBOX_COLUMN structures, one for each column defined. The values in these structures may be modified (in-place) and updated using SetColumns. Modifying the structures has no effect until SetColumns is called.
The array returned by GetColumns is owned by the combo box. It should be used right away and not be saved, as it is only valid until GetColumns is called again or until another function which retrieves the column definitions internally is used (for example SetColumns, MakeColumnOptimal or SetEditAlign). An application must not free the array or the column titles it addresses and must not write to the strings. To change a column title, the application can replace the lpszTitle pointer in the returned array with a pointer to its own string before calling SetColumns, or use SetHeader. The lpszOrig member must not be changed; it is used by the combo box to free the column titles it allocated.
The number of columns can only be modified if the combo box control is empty.
In a simple combo box or a dropdown combo box, SetColumns re-creates the edit control (a SFTBOXN_EDITCREATED notification is sent) and replaces the text in the edit control portion with the text of the currently selected item. If there is no selected item, the edit control portion is cleared.
To define the last column as open-ended use SetOpenEnded. An open-ended last column will display the complete text specified for the last (or only) column and never truncate any data. A fixed-width last column is defined with a specified width and any data which doesn't fit is truncated.
Due to the variable number of levels and the resulting hierarchical display, the width of the first column is always treated as a minimum width. The text portion of the first column will always be at least of the specified width, no matter what level the item is on. This can result in the first column being much wider than the defined width. See GetOverheadWidth for additional information.
An application should use RecalcHorizontalExtent or SetHorizontalExtent to recalculate or set the optimal horizontal scrolling extent.
static void InitColorList(HWND hwndBox, COLORREF custom, COLORREF selected)
{
SFTBOX_COLUMN aCols[2];
LONG index;
int i;
InitColumn(&aCols[0], 0, 100, TEXT("Color"));
InitColumn(&aCols[1], 1, 100, TEXT("Description"));
SftBox_SetColumns(hwndBox, 2, aCols);
SftBox_SetShowHeaderDropDown(hwndBox, TRUE);// Column titles in the dropdown only
SftBox_SetDroppedHeight(hwndBox, 12); // Show up to 12 items
SftBox_SetDropDownOptimalWidth(hwndBox, TRUE);// The dropdown is as wide as its columns
SftBox_SetDisableNoScroll(hwndBox, TRUE); // Scroll bars always shown, needed for the sizing box
SftBox_SetShowResizer(hwndBox, TRUE); // The user can resize the dropdown
SftBox_SetDarkMode(hwndBox, SFTBOX_DARKMODE_AUTO);
void CMainDlg::InitColorList(CSftBox& box, COLORREF custom, COLORREF selected) { SFTBOX_COLUMN aCols[2]; LONG index; InitColumn(&aCols[0], 0, 100, _T("Color")); InitColumn(&aCols[1], 1, 100, _T("Description")); box.SetColumns(2, aCols); box.SetShowHeaderDropDown(TRUE); // Column titles in the dropdown only box.SetDroppedHeight(12); // Show up to 12 items box.SetDropDownOptimalWidth(TRUE); // The dropdown is as wide as its columns box.SetDisableNoScroll(TRUE); // Scroll bars always shown, needed for the sizing box box.SetShowResizer(TRUE); // The user can resize the dropdown box.SetDarkMode(SFTBOX_DARKMODE_AUTO); // Register the size of the cell pictures before adding items.
See Also C/C++ API | Categories | Notifications