Sets the optimal column width so that the text and pictures of all items can be displayed without being clipped horizontally.
C
void WINAPI SftBox_MakeColumnOptimal(HWND hwndCtl, int iCol, LONG maximum);
C++
void CSftBox::MakeColumnOptimal(int iCol, LONG maximum);
hwndCtl
The window handle of the combo box control.
iCol
The zero-based column number to resize so text and pictures are completely shown. Specify -1 to resize all columns optimally.
maximum
Defines the maximum number of items to be considered for width calculation. Specify a number less than or equal to 0 to consider all items. If a combo box contains many items, scanning all items may be extremely slow, as each cell's width needs to be calculated. Using an application defined maximum number, the calculation can be limited to maximum items. This results in better response time, yet some items which are not within the number of scanned items may still be clipped.
The MakeColumnOptimal function sets the optimal column width so that the text and pictures of all items can be displayed without being clipped horizontally.
MakeColumnOptimal resizes a specified column or all columns to the optimal width so that the column header and each cell can be completely displayed without being truncated or clipped. CalcOptimalColumnWidth can be used to calculate a column's optimal width without resizing the column. The column width can be changed using SetColumns.
The width calculation is limited to visible items. Items which are not visible because their parent items are collapsed are not included in the width calculation.
By changing combo box attributes, the optimal column width may change. Adding items, setting new cell pictures and changing cell text are a few of the actions that can affect the optimal column width. The column width may have to be set again to allow items to be completely visible. The combo box control does not automatically adjust column widths.
The last (or only) column may be an open-ended column (see SetOpenEnded). An open-ended column will always use at least the space remaining between the previous column and the right edge of the static portion or dropdown portion. MakeColumnOptimal should be used even with an open-ended column, so the column width is optimal in case the user reorders the columns.
Individual cells can be excluded from optimal column width calculation by setting the SFTBOXCELL_IGNORE value in the flag2 member of the SFTBOX_CELL structure (see SetCellInfo).
In a combo box using a virtual data source, items can be excluded from optimal column width calculation by setting the SFTBOXITEM_IGNORE value in the flag2 member of the SFTBOX_ITEM structure.
for (i = 0 ; i < COLOR_COUNT ; ++i) {
index = SftBox_AddString(hwndBox, m_aColors[i].lpszName);
SftBox_SetText(hwndBox, index, 1, m_aColors[i].lpszDesc);
SftBox_SetItemData(hwndBox, index, m_aColors[i].color);
SetColorSample(hwndBox, index, m_aColors[i].color);
}
SftBox_MakeColumnOptimal(hwndBox, -1, 0); // Make all columns optimal
SftBox_RecalcHorizontalExtent(hwndBox, 0);
// Select the item with the requested color, searching after the custom color
index = SftBox_FindItem(hwndBox, CUSTOM_INDEX + 1, selected);
SftBox_SetCurSel(hwndBox, index >= 0 ? index : CUSTOM_INDEX);
}
static COLORREF GetSelectedColor(HWND hwndBox)
for (int i = 0 ; i < COLOR_COUNT ; ++i) {
index = box.AddString(m_aColors[i].lpszName);
box.SetText(index, 1, m_aColors[i].lpszDesc);
box.SetItemData(index, m_aColors[i].color);
SetColorSample(box, index, m_aColors[i].color);
}
box.MakeColumnOptimal(-1, 0); // Make all columns optimal
box.RecalcHorizontalExtent(0);
// Select the item with the requested color, searching after the custom color
index = box.FindItem(CUSTOM_INDEX + 1, selected);
box.SetCurSel(index >= 0 ? index : CUSTOM_INDEX);
}
COLORREF CMainDlg::GetSelectedColor(const CSftBox& box) constSee Also C/C++ API | Categories | Notifications