ItemBrowserDlg.cpp
上传用户:fuyouda
上传日期:2015-08-19
资源大小:6876k
文件大小:4k
源码类别:

家庭/个人应用

开发平台:

Visual C++

  1. // ItemBrowserDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "DAC_VCDEMO.h"
  5. #include "ItemBrowserDlg.h"
  6. #include "DAC_VCDEMODlg.h"
  7. #include "DACLTSDK.h"
  8. #include "ItemStatusDlg.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // ItemBrowserDlg dialog
  16. ItemBrowserDlg::ItemBrowserDlg(CWnd* pParent /*=NULL*/)
  17. : CDialog(ItemBrowserDlg::IDD, pParent)
  18. {
  19. //{{AFX_DATA_INIT(ItemBrowserDlg)
  20. //}}AFX_DATA_INIT
  21. }
  22. void ItemBrowserDlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(ItemBrowserDlg)
  26. DDX_Control(pDX, IDC_LIST, m_List);
  27. DDX_Control(pDX, IDC_EDIT2, m_Edit2);
  28. DDX_Control(pDX, IDC_EDIT1, m_Edit1);
  29. DDX_Control(pDX, IDC_TREE1, m_Tree);
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(ItemBrowserDlg, CDialog)
  33. //{{AFX_MSG_MAP(ItemBrowserDlg)
  34. ON_BN_CLICKED(IDRefresh, OnRefresh)
  35. ON_BN_CLICKED(IDAdd, OnAdd)
  36. ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchanged)
  37. ON_LBN_SELCHANGE(IDC_LIST, OnSelchange)
  38. ON_WM_SHOWWINDOW()
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // ItemBrowserDlg message handlers
  43. void ItemBrowserDlg::OnRefresh() 
  44. {
  45. m_Edit1.GetWindowText(ItemName);
  46. ItemStatusDlg Status;
  47. Status.DoModal();
  48. }
  49. void ItemBrowserDlg::OnAdd() 
  50. {
  51. CString name;
  52. CDAC_VCDEMODlg *pWnd;
  53. pWnd = (CDAC_VCDEMODlg *)AfxGetMainWnd();
  54. m_Edit1.GetWindowText(name);
  55. name.TrimLeft();
  56. name.TrimRight();
  57. pWnd->AddItem(name);
  58. }
  59. void ItemBrowserDlg::BrowseItems()
  60. {
  61. VARIANT ItemNames;
  62. VariantInit(&ItemNames);
  63. DWORD I, Count;
  64. HTREEITEM hItem= m_Tree.GetSelectedItem();
  65. if(hItem==NULL)return; 
  66. m_List.ResetContent();
  67.     Count = ASDAC_BrowseItems(ServerHandle, 2, "*", 0, 0, &ItemNames);
  68.     if(Count>0)
  69. {
  70. COleSafeArray Names;
  71. BSTR *pbName;
  72. Names.Attach(ItemNames);
  73. Names.AccessData((LPVOID*)&pbName);
  74. for(I=0;I<Count;I++)
  75. {
  76. CString name=pbName[I];
  77. m_List.AddString(name);
  78. }
  79. Names.Detach();
  80.     }
  81. m_Tree.Expand(hItem,TVE_EXPAND);
  82. /*
  83. char Name[128];
  84. int Count;
  85.     Count = ASDAC_BrowseItems(ServerHandle, 2);
  86.     for(int i=0; i<Count; i++)
  87. {
  88.         AS_GetItemName(m_pView->m_hConnect,i,Name,127);
  89. m_List.AddString(Name);
  90.     }
  91. */
  92. }
  93. void ItemBrowserDlg::BrowseBranch()
  94. {
  95. HTREEITEM hItem= m_Tree.GetSelectedItem();
  96. if(hItem==NULL)return; 
  97.     ChangeBrowsePosition(hItem);
  98.     BrowseItems();
  99. if(!m_Tree.ItemHasChildren(hItem))
  100. {
  101. int I, Count;
  102. VARIANT ItemNames;
  103. VariantInit(&ItemNames);
  104.         Count = ASDAC_BrowseItems(ServerHandle, 1,"*",0,0,&ItemNames);
  105.         if(Count>0)
  106. {
  107. COleSafeArray Names;
  108. BSTR *pbName;
  109. Names.Attach(ItemNames);
  110. Names.AccessData((LPVOID*)&pbName);
  111. for(I=0;I<Count;I++)
  112. {
  113. CString name=pbName[I];
  114. m_Tree.InsertItem(name,hItem,NULL);
  115. }
  116. Names.Detach();
  117.         }
  118. m_Tree.Expand(hItem,TVE_EXPAND);
  119.     }
  120. }
  121. void ItemBrowserDlg::ChangeBrowsePosition(HTREEITEM hItem)
  122. {
  123. HTREEITEM root;
  124. root=m_Tree.GetRootItem();
  125. CString name;
  126. if(hItem==root)
  127. {
  128. ASDAC_ChangeBrowsePosition(ServerHandle,1, "");
  129. }
  130. else
  131. {
  132. ChangeBrowsePosition(m_Tree.GetParentItem(hItem));
  133. name=m_Tree.GetItemText(hItem);
  134. ASDAC_ChangeBrowsePosition(ServerHandle,2, name);
  135. }
  136. }
  137. void ItemBrowserDlg::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) 
  138. {
  139. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  140. // TODO: Add your control notification handler code here
  141. BrowseBranch();
  142. *pResult = 0;
  143. }
  144. void ItemBrowserDlg::OnSelchange() 
  145. {
  146. int nIndex = m_List.GetCurSel();
  147. if(nIndex!=LB_ERR)
  148. {
  149. CString name;
  150. char buf[128];
  151. m_List.GetText(nIndex, name);
  152. if(ASDAC_GetItemFullName(ServerHandle, name, buf, 128))
  153. {
  154. m_Edit1.SetWindowText(buf);
  155. }
  156. }
  157. }
  158. void ItemBrowserDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
  159. {
  160. CDialog::OnShowWindow(bShow, nStatus);
  161. HTREEITEM Item=m_Tree.InsertItem("ROOT");
  162. m_Tree.SetItemState(Item, TVIS_SELECTED ,TVIS_STATEIMAGEMASK);
  163. BrowseBranch();
  164. }