RDCDLG.CPP
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:5k
源码类别:

Windows编程

开发平台:

Visual C++

  1. // RDCDlg.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. #include "stdafx.h"
  13. #include "MDIBind.h"
  14. #include "rdc.h"
  15. #include "MDIDoc.h"
  16. #include "mainfrm.h"
  17. #include "RDCFrm.h"
  18. #include "RDCDlg.h"
  19. #include "rdocols.h"
  20. #include "rdocol.h"
  21. #include "rdoReslt.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /////////////////////////////////////////////////////////////////////////////
  28. // COpenControlsDlg dialog
  29. COpenControlsDlg::COpenControlsDlg(const CMDIBindDoc* pDocument,CWnd* pParent /*=NULL*/)
  30. : CDialog(COpenControlsDlg::IDD, pParent)
  31. {
  32. //{{AFX_DATA_INIT(COpenControlsDlg)
  33. m_ColName = pDocument->m_boundCol;
  34. //}}AFX_DATA_INIT
  35. if(pDocument->m_pRDC!=NULL)
  36. m_pRDCView=(CRDCView*) pDocument->m_pRDC->GetParent();
  37. //you could change m_pRDCView to ponter to RDC itself
  38. else
  39. m_pRDCView=NULL;
  40. m_CurrentSel=-1;
  41. }
  42. void COpenControlsDlg::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CDialog::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(COpenControlsDlg)
  46. DDX_CBString(pDX, IDC_COLUMN, m_ColName);
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(COpenControlsDlg, CDialog)
  50. //{{AFX_MSG_MAP(COpenControlsDlg)
  51. ON_CBN_DROPDOWN(IDC_COLUMN, OnDropdownColumns)
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54. /////////////////////////////////////////////////////////////////////////////
  55. // COpenControlsDlg message handlers
  56. BOOL COpenControlsDlg::OnInitDialog()
  57. {
  58. CDialog::OnInitDialog();
  59. CListBox* pListBox = (CListBox*) GetDlgItem(IDC_RDCLIST);
  60. CMainFrame* pMainFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
  61. ASSERT(pMainFrame->IsKindOf(RUNTIME_CLASS(CMainFrame)));
  62. // iterate through all MDI windows
  63. CMDIChildWnd* pMDIChild = pMainFrame->MDIGetActive();
  64. if(pMDIChild != NULL)
  65. pMDIChild = (CRDCFrame*) pMDIChild->GetWindow(GW_HWNDLAST);
  66. while (pMDIChild != NULL)
  67. {
  68. CString strTitle;
  69. int nIndex;
  70. if(pMDIChild->IsKindOf(RUNTIME_CLASS(CRDCFrame)))
  71. { // only RDC windows
  72. CRDCView* pRDCView = (CRDCView*)pMDIChild->GetActiveView();
  73. ASSERT(pRDCView->IsKindOf(RUNTIME_CLASS(CRDCView)));
  74. // get the window's title
  75. pMDIChild->GetWindowText(strTitle);
  76. strTitle=strTitle+_T(": ")+pRDCView->m_pRDCCtl->GetCaption();
  77. // add the window to the list
  78. nIndex = pListBox->AddString(strTitle);
  79. if(m_pRDCView!=NULL &&
  80. pRDCView==m_pRDCView) // you'd compare RDC themselves as well
  81. {   // select nIndex item only if
  82. // m_pRDCCtl==the control currenty assigned
  83. pListBox->SetCurSel(nIndex);
  84. }
  85. // store a pointer to the frame
  86. pListBox->SetItemData(nIndex, (DWORD)pMDIChild);
  87. }
  88. pMDIChild = (CRDCFrame*) pMDIChild->GetWindow(GW_HWNDPREV);
  89. } // while
  90. int cElements = pListBox->GetCount();
  91. pListBox->SetFocus();
  92. return TRUE;  // return TRUE unless you set the focus to a control
  93.   // EXCEPTION: OCX Property Pages should return FALSE
  94. }
  95. void COpenControlsDlg::OnOK()
  96. {
  97. CListBox* pListBox = (CListBox*) GetDlgItem(IDC_RDCLIST);
  98. int cElements = pListBox->GetCount();
  99. int nSelection= pListBox->GetCurSel();  // get the selected item
  100. if(cElements > 0 && nSelection >= 0)
  101. {   // can only select a window if at least one item is selected
  102. // get the pointer to the frame
  103. m_pMDIChild = (CRDCFrame*) pListBox->GetItemData(nSelection);
  104. ASSERT(m_pMDIChild->IsKindOf(RUNTIME_CLASS(CRDCFrame)));
  105. // now use ActiveView() rather than MDIActivate()
  106. // get a pointer to the active view in the frame
  107. m_pRDCView = (CRDCView*) m_pMDIChild->GetActiveView();
  108. ASSERT(m_pRDCView->IsKindOf(RUNTIME_CLASS(CRDCView)));
  109. } //if
  110. CDialog::OnOK();
  111. }
  112. /////////////////////////////////////////////////////////////////////////////
  113. // Refill the Combo List with columns names from currently selected RDC
  114. void COpenControlsDlg::OnDropdownColumns()
  115. {
  116. CListBox* pListBox = (CListBox*) GetDlgItem(IDC_RDCLIST);
  117. CComboBox* pComboBox = (CComboBox*) GetDlgItem(IDC_COLUMN);
  118. int nSelection=pListBox->GetCurSel();
  119. if(nSelection<0 || nSelection==m_CurrentSel)
  120. return; // nothing to change in Combo box
  121. m_CurrentSel=nSelection;
  122. pComboBox->ResetContent( ); // clear old columns
  123. m_pMDIChild = (CRDCFrame*) pListBox->GetItemData(nSelection);
  124. ASSERT(m_pMDIChild->IsKindOf(RUNTIME_CLASS(CRDCFrame)));
  125. // now use ActiveView() rather than MDIActivate()
  126. // get a pointer to the active view in the frame
  127. m_pRDCView = (CRDCView*) m_pMDIChild->GetActiveView();
  128. ASSERT(m_pRDCView->IsKindOf(RUNTIME_CLASS(CRDCView)));
  129. CRdc* pRDC=m_pRDCView->m_pRDCCtl;
  130. ASSERT(pRDC!=NULL);
  131. CrdoResultset pResult;  // resultset from RDC
  132. CrdoColumns pColumns;   // columns from resultset
  133. pResult=pRDC->GetResultset();
  134. if(pResult!=NULL && (pColumns=pResult.GetRdoColumns())!=NULL)
  135. {
  136. long ncol=pColumns.GetCount();
  137. CrdoColumn pCol; // element from columns collection
  138. for(long icol=0; icol<ncol; icol++)
  139. {
  140. pCol=pColumns.GetItem(COleVariant(icol)); //get i-column
  141. pComboBox->AddString(pCol.GetName());//add its name to the list
  142. }
  143. pComboBox->SetCurSel(0); // no old element valid if new RDC
  144. }
  145. }