LB_SETHORIZONTALEXTENT

3.0

LB_SETHORIZONTALEXTENT
wParam = (WPARAM) cxExtent; /* horizontal scroll width */
lParam = 0L;                /* not used, must be zero  */

An application sends the LB_SETHORIZONTALEXTENT message to set the width, in pixels, by which a list box can be scrolled horizontally. If the size of the list box is smaller than this value, the horizontal scroll bar horizontally scrolls items in the list box. If the size of the list box is equal to or greater than this value, the horizontal scroll bar is hidden.

Parameters

cxExtent

Value of wParam. Specifies the number of pixels by which the list box can be scrolled.

Return Value

This message does not return a value.

Comments

To respond to the LB_SETHORIZONTALEXTENT message, the list box must have been defined with the WS_HSCROLL style.

By default, the horizontal extent of a list box is zero. Windows does not display the scroll bar unless the horizontal extent is set to a value greater than the width, in pixels, of the client area of the list box.

Example

This example sets the horizontal extent of a list box based on the width of the string about to be added to the list box. The horizontal extent is set if the string is wider than the widest string in the list box and is wider than the client area of the list box.

DWORD dwStringExt;
HDC hdcLB;
PSTR pszString;
TEXTMETRIC tm;
WORD wLongest;
WORD wLBWidth;

dwStringExt = GetTextExtent(hdcLB, (LPSTR) pszString,
    strlen(pszString)) + tm.tmAveCharWidth;


if ((LOWORD(dwStringExt) > wLongest) &&
        (LOWORD(dwStringExt) > wLBWidth)) {
    SendDlgItemMessage(hDlg, ID_MYLISTBOX, LB_SETHORIZONTALEXTENT,
        LOWORD(dwStringExt), 0L);
    wLongest = LOWORD(dwStringExt);
}

SendDlgItemMessage(hDlg, ID_MYLISTBOX, LB_ADDSTRING, 0,
    (LPARAM) ((LPCSTR) pszString));

See Also

LB_GETHORIZONTALEXTENT