ID Number: Q78241
3.00
WINDOWS
Summary:
Although there is no single message that restricts the number of
entries (lines) allowed in a list box, the limit can be imposed
through the use of subclassing.
More Information:
The following code fragment is an excerpt from a subclassing function
that can be used to restrict the number of entries in a list box to no
more than the constant MAXENTRIES where the lpfnOldLBFn variable
points to the original list box window procedure:
long FAR PASCAL SubClassFn(hWnd, message, wParam, lParam)
HWND hWnd;
unsigned message;
WORD wParam;
LONG lParam;
{
int iCount;
switch (message)
{
case LB_ADDSTRING:
case LB_INSERTSTRING:
iCount = SendMessage(hWnd, LB_GETCOUNT, 0, 0L);
if (iCount > MAXENTRIES)
{ /* Insert action here to inform user of limit violation */
break;
}
/* fall through if less entries than maximum */
default:
return CallWindowProc(lpfnOldLBProc, hWnd, message, wParam,
lParam);
}
}
Additional reference words: 3.00 list box