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.

190 lines
4.4 KiB

  1. /*++
  2. Module Name:
  3. MRoots.cpp
  4. Abstract:
  5. This module contains the Implementation of CMultiRoots.
  6. This class displays the Pick DFS Roots Dialog.
  7. */
  8. #include "stdafx.h"
  9. #include "utils.h"
  10. #include "MRoots.h"
  11. #include "dfshelp.h"
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMultiRoots
  14. CMultiRoots::CMultiRoots() : m_pRootList(NULL)
  15. {
  16. }
  17. CMultiRoots::~CMultiRoots()
  18. {
  19. FreeNetNameList(&m_SelectedRootList);
  20. }
  21. HRESULT CMultiRoots::Init(BSTR i_bstrScope, ROOTINFOLIST *i_pRootList)
  22. {
  23. if (!i_bstrScope || !*i_bstrScope ||
  24. !i_pRootList || !(i_pRootList->size()))
  25. return E_INVALIDARG;
  26. SAFE_SYSFREESTRING(&m_bstrScope);
  27. m_bstrScope = i_bstrScope;
  28. SAFE_SYSFREESTRING(&m_bstrText);
  29. HRESULT hr = FormatResourceString(IDS_MROOTS_TEXT, i_bstrScope, &m_bstrText);
  30. RETURN_IF_FAILED(hr);
  31. m_pRootList = i_pRootList;
  32. FreeNetNameList(&m_SelectedRootList);
  33. return S_OK;
  34. }
  35. LRESULT CMultiRoots::OnInitDialog
  36. (
  37. UINT uMsg,
  38. WPARAM wParam,
  39. LPARAM lParam,
  40. BOOL& bHandled
  41. )
  42. {
  43. SetDlgItemText(IDC_MROOTS_TEXT, m_bstrText);
  44. HWND hwnd = GetDlgItem(IDC_MROOTS_LIST);
  45. HIMAGELIST hImageList = NULL;
  46. int nIconIDs[] = {IDI_16x16_FTROOT, IDI_16x16_SAROOT};
  47. HRESULT hr = CreateSmallImageList(
  48. _Module.GetResourceInstance(),
  49. nIconIDs,
  50. sizeof(nIconIDs) / sizeof(nIconIDs[0]),
  51. &hImageList);
  52. if (SUCCEEDED(hr))
  53. {
  54. ListView_SetImageList(hwnd, hImageList, LVSIL_SMALL);
  55. for(ROOTINFOLIST::iterator i = m_pRootList->begin(); i != m_pRootList->end(); i++)
  56. {
  57. if ((*i)->bstrRootName)
  58. {
  59. LVITEM lvItem = {0};
  60. lvItem.mask = LVIF_TEXT | LVIF_IMAGE;
  61. lvItem.pszText = (*i)->bstrRootName;
  62. lvItem.iSubItem = 0;
  63. lvItem.iImage = ((*i)->enumRootType == DFS_TYPE_FTDFS ? 0 : 1);
  64. ListView_InsertItem(hwnd, &lvItem);
  65. }
  66. }
  67. }
  68. return TRUE; // Let the system set the focus
  69. }
  70. /*++
  71. This function is called when a user clicks the ? in the top right of a property sheet
  72. and then clciks a control, or when they hit F1 in a control.
  73. --*/
  74. LRESULT CMultiRoots::OnCtxHelp(
  75. IN UINT i_uMsg,
  76. IN WPARAM i_wParam,
  77. IN LPARAM i_lParam,
  78. IN OUT BOOL& io_bHandled
  79. )
  80. {
  81. LPHELPINFO lphi = (LPHELPINFO) i_lParam;
  82. if (!lphi || lphi->iContextType != HELPINFO_WINDOW || lphi->iCtrlId < 0)
  83. return FALSE;
  84. ::WinHelp((HWND)(lphi->hItemHandle),
  85. DFS_CTX_HELP_FILE,
  86. HELP_WM_HELP,
  87. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_MROOTS);
  88. return TRUE;
  89. }
  90. /*++
  91. This function handles "What's This" help when a user right clicks the control
  92. --*/
  93. LRESULT CMultiRoots::OnCtxMenuHelp(
  94. IN UINT i_uMsg,
  95. IN WPARAM i_wParam,
  96. IN LPARAM i_lParam,
  97. IN OUT BOOL& io_bHandled
  98. )
  99. {
  100. ::WinHelp((HWND)i_wParam,
  101. DFS_CTX_HELP_FILE,
  102. HELP_CONTEXTMENU,
  103. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_MROOTS);
  104. return TRUE;
  105. }
  106. LRESULT CMultiRoots::OnOK
  107. (
  108. WORD wNotifyCode,
  109. WORD wID,
  110. HWND hWndCtl,
  111. BOOL& bHandled
  112. )
  113. {
  114. CWaitCursor wait;
  115. FreeNetNameList(&m_SelectedRootList);
  116. HRESULT hr = S_OK;
  117. HWND hwnd = GetDlgItem(IDC_MROOTS_LIST);
  118. int nIndex = -1;
  119. TCHAR szText[MAX_PATH];
  120. do {
  121. while (-1 != (nIndex = ListView_GetNextItem(hwnd, nIndex, LVNI_SELECTED)))
  122. {
  123. ListView_GetItemText(hwnd, nIndex, 0, szText, MAX_PATH);
  124. NETNAME* pCurrent = new NETNAME;
  125. BREAK_OUTOFMEMORY_IF_NULL(pCurrent, &hr);
  126. pCurrent->bstrNetName = szText;
  127. if (!(pCurrent->bstrNetName))
  128. {
  129. delete pCurrent;
  130. hr = E_OUTOFMEMORY;
  131. break;
  132. }
  133. m_SelectedRootList.push_back(pCurrent);
  134. }
  135. } while (0);
  136. if (FAILED(hr))
  137. {
  138. FreeNetNameList(&m_SelectedRootList);
  139. DisplayMessageBoxForHR(hr);
  140. return FALSE;
  141. }
  142. EndDialog(S_OK);
  143. return TRUE;
  144. }
  145. LRESULT CMultiRoots::OnCancel
  146. (
  147. WORD wNotifyCode,
  148. WORD wID,
  149. HWND hWndCtl,
  150. BOOL& bHandled
  151. )
  152. {
  153. EndDialog(S_FALSE);
  154. return(true);
  155. }