List boxes are WC_LISTBOX class windows and are predefined by the system. Applications can create list boxes by calling WinCreateWindow, using WC_LISTBOX as the window-class parameter.

A list box passes notification messages to its owner window, so an application uses its client window, rather than the frame window, as the owner of the list. The client-window procedure receives the messages sent from the list box. For example, to create a list box that completely fills the client area of a frame window, an application would make the client window the owner and parent of the list-box window, and make the list-box window the same size as the client window. This is shown in the following code fragment.

    #define ID_LISTWINDOW   250

    HWND hwndClient,hwndList;
    RECTL rcl;

                                              /* How big is the
                                               client window? */
    WinQueryWindowRect(hwndClient, &rcl);

                                              /* Make a list-box
                                                window.       */
    hwndList = WinCreateWindow(hwndClient,    /* Parent       */
        WC_LISTBOX,                           /* Class        */
        "",                                   /* Name         */
        WS_VISIBLE | LS_NOADJUSTPOS,          /* Style        */
        0, 0,                                 /* x, y         */
        rcl.xRight, rcl.yTop,                 /* cx, cy       */
        hwndClient,                           /* Owner        */
        HWND_TOP,                             /* Behind       */
        ID_LISTWINDOW,                        /* ID           */
        NULL,                                 /* Control data */
        NULL);                                /* parameters   */

Because the list box draws its own border, and a frame-window border already surrounds the client area of a frame window due to the adjacent frame controls, the effect is a double-thick border around the list box. You can change this effect by calling WinInflateRect to overlap the list-box border with the surrounding frame-window border, resulting in only one list-box border.

Notice that the code specifies the list-box window style LS_NOADJUSTPOS. This ensures that the list box is created exactly the specified size. If the LS_NOADJUSTPOS style is not specified, the list-box height is rounded down, if necessary, to make it a multiple of the item height. Enabling a list box to adjust its height automatically is useful for preventing partial items being displayed at the bottom of a list box.


[Back] [Next]