Limiting the Number of Entries in a List Box

Last reviewed: November 2, 1995
Article ID: Q78241
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

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 3.10 3.50 4.00 95 list box
KBCategory: kbui
KBSubcategory: UsrCtl


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.