Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
3.6 KiB

  1. #include "precomp.h"
  2. /*++
  3. Copyright (c) 1989-2000 Microsoft Corporation
  4. Module Name:
  5. CTree.cpp
  6. Abstract:
  7. Wrapper for some general tree functions
  8. Author:
  9. kinshu created October 15, 2001
  10. --*/
  11. BOOL
  12. CTree::SetLParam(
  13. IN HWND hwndTree,
  14. IN HTREEITEM hItem,
  15. IN LPARAM lParam
  16. )
  17. /*++
  18. CTree::SetLParam
  19. Desc: Sets the lParam of a tree item
  20. Params:
  21. IN HWND hwndTree: The handle to the tree
  22. IN HTREEITEM hItem: The tree item
  23. IN LPARAM lParam: The lParam to set
  24. Return:
  25. TRUE: If the lParam was set properly
  26. FALSE: Otherwise
  27. --*/
  28. {
  29. TVITEM Item;
  30. Item.mask = TVIF_PARAM;
  31. Item.hItem = hItem;
  32. Item.lParam = lParam;
  33. return TreeView_SetItem(hwndTree, &Item);
  34. }
  35. BOOL
  36. CTree::GetLParam(
  37. IN HWND hwndTree,
  38. IN HTREEITEM hItem,
  39. OUT LPARAM* plParam
  40. )
  41. /*++
  42. CTree::GetLParam
  43. Desc: Gets the lParam of a tree item
  44. Params:
  45. IN HWND hwndTree: The handle to the tree
  46. IN HTREEITEM hItem: The tree item
  47. OUT LPARAM* lParam: The lParam will be stored here
  48. Return:
  49. TRUE: If the lParam was obtained properly
  50. FALSE: Otherwise
  51. --*/
  52. {
  53. TVITEM Item;
  54. if (plParam == NULL) {
  55. assert(FALSE);
  56. return FALSE;
  57. }
  58. *plParam = 0;
  59. Item.mask = TVIF_PARAM;
  60. Item.hItem = hItem;
  61. if (TreeView_GetItem(hwndTree, &Item)) {
  62. *plParam = Item.lParam;
  63. return TRUE;
  64. }
  65. return FALSE;
  66. }
  67. HTREEITEM
  68. CTree::FindChild(
  69. IN HWND hwndTree,
  70. IN HTREEITEM hItemParent,
  71. IN LPARAM lParam
  72. )
  73. /*++
  74. CTree::FindChild
  75. Desc: Given a parent item and a lParam, finds the first child of the parent, with
  76. that value of lParam. This function only searches in the next level and not all
  77. the generations of the parent
  78. Params:
  79. IN HWND hwndTree: The handle to the tree
  80. IN HTREEITEM hItemParent: The hItem of the parent
  81. IN LPARAM lParam: The lParam to search for
  82. Return: The handle to the child or NULL if it does not exist
  83. --*/
  84. {
  85. HTREEITEM hItem = TreeView_GetChild(hwndTree, hItemParent);
  86. while (hItem) {
  87. LPARAM lParamOfItem;
  88. if (!GetLParam(hwndTree, hItem, &lParamOfItem)) {
  89. assert(FALSE);
  90. return NULL;
  91. }
  92. if (lParamOfItem == lParam) {
  93. return hItem;
  94. } else {
  95. hItem = TreeView_GetNextSibling(hwndTree, hItem);
  96. }
  97. }
  98. return NULL;
  99. }
  100. BOOL
  101. CTree::GetTreeItemText(
  102. IN HWND hwndTree,
  103. IN HTREEITEM hItem,
  104. OUT PTSTR pszText,
  105. IN UINT cchText
  106. )
  107. /*++
  108. CTree::GetTreeItemText
  109. Desc: Gets the text of a tree view item
  110. Params:
  111. IN HWND hwndTree: The handle to the tree
  112. IN HTREEITEM hItem: The item whose text we want to find
  113. OUT TCHAR *pszText: This will store the text
  114. IN UINT cchText: Number of TCHARS that can be stored in pszText
  115. Return:
  116. TRUE: successful
  117. FALSE: Otherwise
  118. --*/
  119. {
  120. TVITEM Item;
  121. Item.mask = TVIF_TEXT;
  122. Item.hItem = hItem;
  123. Item.pszText = pszText;
  124. Item.cchTextMax = cchText;
  125. return TreeView_GetItem(hwndTree,&Item);
  126. }