home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / wordpad / listdlg.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  2KB  |  64 lines

  1. // listdlg.cpp : Defines the class behaviors for the application.
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "resource.h"
  15. #include "listdlg.h"
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. BEGIN_MESSAGE_MAP(CListDlg, CDialog)
  23.     //{{AFX_MSG_MAP(CListDlg)
  24.     ON_LBN_DBLCLK(IDC_LISTDIALOG_LIST, OnOK)
  25.     //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27.  
  28. CListDlg::CListDlg(UINT idStrDlgTitle, UINT idStrListTitle,
  29.     const CStringList& listItems, int nDefSel) : CDialog(CListDlg::IDD),
  30.     m_listItems(listItems)
  31. {
  32.     VERIFY(m_strDlgTitle.LoadString(idStrDlgTitle));
  33.     VERIFY(m_strListTitle.LoadString(idStrListTitle));
  34.     m_nSelection = nDefSel;
  35. }
  36.  
  37. BOOL CListDlg::OnInitDialog()
  38. {
  39.     SetWindowText(m_strDlgTitle);
  40. // fix this
  41.     SetDlgItemText(IDC_STATIC_HEADING, m_strListTitle);
  42.     CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LISTDIALOG_LIST);
  43.     ASSERT(pListBox != NULL);
  44.     // fill with document templates in list
  45.  
  46.     POSITION pos = m_listItems.GetHeadPosition();
  47.     while (pos != NULL)
  48.     {
  49.          if ( pListBox->AddString(m_listItems.GetNext(pos)) == -1)
  50.             return FALSE;
  51.     }
  52.     pListBox->SetCurSel(m_nSelection);
  53.  
  54.     return CDialog::OnInitDialog();
  55. }
  56.  
  57. void CListDlg::OnOK()
  58. {
  59.     CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LISTDIALOG_LIST);
  60.     ASSERT(pListBox != NULL);
  61.     m_nSelection = pListBox->GetCurSel();
  62.     CDialog::OnOK();
  63. }
  64.