home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / database / daoview / dlgparam.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  2.8 KB  |  107 lines

  1. // DlgParam.cpp : implementation file
  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 "DaoView.h"
  15. #include "DlgParam.h"
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CDlgParams dialog
  24.  
  25.  
  26. CDlgParams::CDlgParams(CWnd* pParent /*=NULL*/)
  27.     : CDialog(CDlgParams::IDD, pParent)
  28. {
  29.     //{{AFX_DATA_INIT(CDlgParams)
  30.         // NOTE: the ClassWizard will add member initialization here
  31.     //}}AFX_DATA_INIT
  32. }
  33.  
  34.  
  35. void CDlgParams::DoDataExchange(CDataExchange* pDX)
  36. {
  37.     CDialog::DoDataExchange(pDX);
  38.     //{{AFX_DATA_MAP(CDlgParams)
  39.     DDX_Control(pDX, IDC_LISTVIEW1, m_ctlList);
  40.     //}}AFX_DATA_MAP
  41. }
  42.  
  43.  
  44. BEGIN_MESSAGE_MAP(CDlgParams, CDialog)
  45.     //{{AFX_MSG_MAP(CDlgParams)
  46.     ON_NOTIFY(LVN_ENDLABELEDIT, IDC_LISTVIEW1, OnEndlabeleditListview1)
  47.     //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CDlgParams message handlers
  52.  
  53. void CDlgParams::SetInfo(CDaoDatabase* pDB,LPCTSTR lpszQueryDef)
  54. {
  55.     m_pDB = pDB;
  56.     m_strQueryDef = lpszQueryDef;
  57. }
  58.  
  59.  
  60. BOOL CDlgParams::OnInitDialog()
  61. {
  62.     CDialog::OnInitDialog();
  63.  
  64.     m_ctlList.AddColumn(_T("Value    "),0);
  65.     m_ctlList.AddColumn(_T("Parameter Name"),1);
  66.  
  67.     CDaoQueryDef qd(m_pDB);
  68.     CDaoParameterInfo paramInfo;
  69.     int nParams;
  70.     try{
  71.         qd.Open(m_strQueryDef);
  72.         nParams = qd.GetParameterCount();
  73.         for (int i=0;i < nParams;i++){
  74.             qd.GetParameterInfo(i,paramInfo);
  75.             COleVariant var = qd.GetParamValue(i);
  76.             m_ctlList.AddItem(i,0,CCrack::strVARIANT(var));
  77.             m_ctlList.AddItem(i,1,paramInfo.m_strName);
  78.         }
  79.     }
  80.     catch(CDaoException* e){
  81.         // ... Do nothing.  Used to catch security violations opening tables.
  82.         e->Delete();
  83.     }
  84.     qd.Close();
  85.  
  86.     return TRUE;  // return TRUE unless you set the focus to a control
  87.                   // EXCEPTION: OCX Property Pages should return FALSE
  88. }
  89.  
  90. void CDlgParams::OnEndlabeleditListview1(NMHDR* pNMHDR, LRESULT* pResult)
  91. {
  92.     LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
  93.  
  94.     m_ctlList.SetItemText(pDispInfo->item.iItem,pDispInfo->item.iSubItem,pDispInfo->item.pszText);
  95.     CDaoQueryDef qd(m_pDB);
  96.     try{
  97.         qd.Open(m_strQueryDef);
  98.         qd.SetParamValue(pDispInfo->item.iItem,COleVariant(pDispInfo->item.pszText, VT_BSTRT));
  99.     }
  100.     catch(CDaoException* e){
  101.         // ... Do nothing.  Used to catch security violations opening tables.
  102.         e->Delete();
  103.     }
  104.     qd.Close();
  105.     *pResult = 0;
  106. }
  107.