home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c08 / dynalist / tbseldlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  2.1 KB  |  91 lines

  1. // DaoTableSelectDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "DynaList.h"
  6. #include "TbSelDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CDaoTableSelectDlg dialog
  16.  
  17.  
  18. CDaoTableSelectDlg::CDaoTableSelectDlg(CWnd* pParent /*=NULL*/)
  19.     : CDialog(CDaoTableSelectDlg::IDD, pParent)
  20. {
  21.     //{{AFX_DATA_INIT(CDaoTableSelectDlg)
  22.         // NOTE: the ClassWizard will add member initialization here
  23.     //}}AFX_DATA_INIT
  24. }
  25.  
  26.  
  27. void CDaoTableSelectDlg::DoDataExchange(CDataExchange* pDX)
  28. {
  29.     CDialog::DoDataExchange(pDX);
  30.     //{{AFX_DATA_MAP(CDaoTableSelectDlg)
  31.     DDX_Control(pDX, IDC_TABLELIST, m_ctlTableList);
  32.     //}}AFX_DATA_MAP
  33. }
  34.  
  35.  
  36. BEGIN_MESSAGE_MAP(CDaoTableSelectDlg, CDialog)
  37.     //{{AFX_MSG_MAP(CDaoTableSelectDlg)
  38.     //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CDaoTableSelectDlg message handlers
  43.  
  44. BOOL CDaoTableSelectDlg::OnInitDialog() 
  45. {
  46.     CDialog::OnInitDialog();
  47.     
  48.     if(!m_pDatabase->IsOpen())
  49.     {
  50.         CButton* pOK = (CButton*)GetDlgItem(IDOK);
  51.         pOK->EnableWindow(FALSE);
  52.         return TRUE;
  53.     }
  54.  
  55.     // Fill the listbox with the table names
  56.     CDaoTableDefInfo tdi;
  57.     int nTables = m_pDatabase->GetTableDefCount();
  58.     for(int i = 0; i < nTables; i++)
  59.     {
  60.         m_pDatabase->GetTableDefInfo(i, tdi);
  61.         m_ctlTableList.AddString(tdi.m_strName);
  62.     }
  63.     
  64.     return TRUE;  // return TRUE unless you set the focus to a control
  65.                   // EXCEPTION: OCX Property Pages should return FALSE
  66. }
  67.  
  68.  
  69. void CDaoTableSelectDlg::OnOK() 
  70. {
  71.     // Extract the table selections and place in member variable
  72.     m_strTables = "";
  73.     int nSelCount = m_ctlTableList.GetSelCount();
  74.     if(nSelCount > 0)
  75.     {
  76.         int* pIndex = new int[nSelCount];
  77.         m_ctlTableList.GetSelItems(nSelCount, pIndex);
  78.         m_ctlTableList.GetText(*pIndex, m_strTables);
  79.         for(int i = 1; i < nSelCount; i++)
  80.         {
  81.             CString strText;
  82.             m_ctlTableList.GetText(*(pIndex + i), strText);
  83.             m_strTables += ", ";
  84.             m_strTables += strText;
  85.         }
  86.  
  87.         delete [] pIndex;
  88.     }
  89.     CDialog::OnOK();
  90. }
  91.