SAMPLE: Implementing a List Box Full of Dialog Boxes

Last reviewed: February 15, 1996
Article ID: Q113189
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows version 3.1

SUMMARY

In some cases, a user interface may require many dialog boxes to be present at one time. It is possible to display these dialog boxes inside of an owner-draw list box by moving the dialog boxes over the area that the list box's items cover.

The LISTDLG sample demonstrates this method of displaying dialog boxes. The sample uses a fixed height, owner-draw list box with a vertical scroll bar to display several modeless dialog boxes. The scroll bar can be used to scroll through the dialog boxes.

LISTDLG can be downloaded as a self-extracting file from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download LISTDLG.EXE (size: 26951 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get LISTDLG.EXE (size: 26951 bytes) 
    

MORE INFORMATION

This sample demonstrates how to implement an owner-draw list box that contains a list of modeless dialog boxes. The sample displays a dialog box containing a list box with the LBS_OWNERDRAWFIXED style. It then creates five modeless dialog boxes and places five entries in the list box. Then, the sample associates a dialog box handle for each entry in the list box by sending an LB_SETITEMDATA message to the list box for each list box entry.

The LISTDLG sample implements an owner-draw list box and shows how to handle the WM_MEASUREITEM and the WM_DRAWITEM messages associated with the list box. When a WM_DRAWITEM message is sent to the owner of the list box, the appropriate modeless dialog box is moved via MoveWindow() to cover the entire area of the list box item specified in the itemID field of the DRAWITEMSTRUCT structure. To show which dialog box (list box item) is currently selected, the WM_CTLCOLOR message is used to change the background and text color of the dialog boxes. When a dialog box is currently selected, its background color will be COLOR_HIGHLIGHT and its text color will be COLOR_HIGHLIGHTTEXT.

The WM_MOUSEACTIVATE, WM_SETFOCUS, and WM_CTLCOLOR messages for the dialog boxes are all handled by the following three generic functions in the source file DIALOG.C:

   BOOL HandleMouseActivate(int nIndex, HWND hDlg)
   BOOL HandleSetFocus(int nIndex, HWND hDlg)
   BOOL HandleCtlColor(int nIndex, HWND hDlg, WORD wParam, LONG lParam)

The "nIndex" parameter is the zero-based list box item index associated with the dialog box and hDlg is a handle to the dialog box. It is important that all dialog boxes that are associated with the list box call these functions when processing the above messages.

To select a dialog box from the list box, just click the left mouse button anywhere on the dialog box, as you would do to select a normal list box item. You can also scroll through the dialog boxes by using the scroll bar on the list box. You can move from one dialog box to the next one in line by choosing the Next button on any dialog box. The focus will scroll around to the first dialog box in the list when the Next button of the last dialog box is chosen. It is important that all dialog boxes that are associated with the list box have a Next button so keyboard mobility is possible.


Additional reference words: 3.10 listbox dialogs scrollbar softlib
KBCategory: kbprg kbfile
KBSubcategory: UsrDlgs


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: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.