Listbox Sample Using Microsoft Foundation Classes

Last reviewed: July 17, 1997
Article ID: Q102828
1.00 1.50 1.51 1.52 | 1.00 2.00 2.10
WINDOWS             | WINDOWS NT
kbprg

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC) included with:

        - Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, and
          1.52
        - Microsoft Visual C++ 32-bit Edition, version 1.0, 2.0, and 2.1
    

This is the 16-bit version of this sample. There is an equivalent 32-bit sample available under the name LSTDDX32.EXE.

SUMMARY

The LSTDDX sample illustrates a technique for filling both an ordinary listbox control and the listbox portion of a combo control with data, and using the Microsoft Foundation Class (MFC) Dialog Data Exchange (DDX) facility to return the selection.

LSTDDX can be found in the Microsoft Software Library.

Download LSTDDX.EXE, 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 LSTDDX.EXE (size: 44838 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \softlib\mslfiles directory
          Get LSTDDX.EXE (size: 44838 bytes) 
    

NOTE: Use the -d option when running LSTDDX.EXE to decompress the file and re-create the proper directory structure.

MORE INFORMATION

A common misconception with regard to DDX is that assigning a value to a DDX variable will cause that data to be loaded into a control. This does in fact happen for edit controls, but not for listbox controls. In order to add items to a listbox the dialog class must use the CListBox::AddString() or CComboBox::AddString() functions. Doing this involves several steps which are illustrated by this sample.

The sample itself was initially created as an MDI application using AppWizard from Visual C++ version 1.0. AppStudio was then used to create a dialog which contains OK and Cancel button plus an edit control (IDC_EDIT1), a combo control (IDC_COMBO1), and a listbox control (IDC_LIST1). The Class Wizard was used to create a class CDialog1 based on CDialog. The files dialog1.h and dialog1.cpp contain the code for this class. Class Wizard was also used to add DDX member variables m_edit1, m_combo1, and m_list1 to dialog1.h. A menu item was added to the view menu (IDR_LIST_DTYPE) using AppStudio, and a message handler added which will call the dialog when the menu item was selected.

The README.TXT file included with the sample explains in more detail how the listboxes are initialized and how data is passed between the calling routine and the dialog procedure.

REFERENCES

Q141498 "SAMPLE: Filling List Box Using MFC's DDX Facility"


Additional reference words: kbinf 1.00 1.50 1.51 1.52 2.00 2.10 2.50 2.51
2.52 3.00 3.10 lstddx32
KBCategory: kbprg
KBSubcategory: MfcUI
Keywords : kb16bitonly MfcUI kbprg
Technology : kbMfc
Version : 1.00 1.50 1.51 1.52 | 1.00 2.00
Platform : NT WINDOWS


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: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.