Source code of Windows XP (NT5)
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.

456 lines
8.4 KiB

  1. /*++
  2. Module Name:
  3. AddToDfs.cpp
  4. Abstract:
  5. This module contains the implementation for CAddToDfs.
  6. This class displays the Add To Dfs Dialog, which is used to add new Junctions Points.
  7. */
  8. #include "stdafx.h"
  9. #include "AddToDfs.h"
  10. #include <shlobj.h>
  11. #include <dsclient.h>
  12. #include "utils.h"
  13. #include "dfshelp.h"
  14. #include "netutils.h"
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CAddToDfs
  17. CAddToDfs::CAddToDfs():m_lTime(1800)
  18. {
  19. }
  20. CAddToDfs::~CAddToDfs()
  21. {
  22. }
  23. HRESULT CAddToDfs::put_ParentPath
  24. (
  25. BSTR i_bstrParentPath
  26. )
  27. {
  28. /*++
  29. Routine Description:
  30. Sets the path of the parent Junction point.
  31. This is used to display in the edit text and append to the entry path.
  32. */
  33. if (!i_bstrParentPath)
  34. return(E_INVALIDARG);
  35. m_bstrParentPath = i_bstrParentPath;
  36. if (!m_bstrParentPath)
  37. return(E_OUTOFMEMORY);
  38. return(S_OK);
  39. }
  40. HRESULT CAddToDfs::get_Comment
  41. (
  42. BSTR *o_bstrComment
  43. )
  44. {
  45. if (!o_bstrComment)
  46. return(E_INVALIDARG);
  47. *o_bstrComment = SysAllocString(m_bstrComment);
  48. if (!*o_bstrComment)
  49. return(E_OUTOFMEMORY);
  50. return(S_OK);
  51. }
  52. HRESULT CAddToDfs::get_EntryPath
  53. (
  54. BSTR *o_bstrEntryPath
  55. )
  56. {
  57. /*++
  58. Routine Description:
  59. Returns the complete entry path of the new Junction point to be created.
  60. */
  61. if (!o_bstrEntryPath)
  62. return(E_INVALIDARG);
  63. *o_bstrEntryPath = SysAllocString(m_bstrEntryPath);
  64. if (!*o_bstrEntryPath)
  65. return(E_OUTOFMEMORY);
  66. return(S_OK);
  67. }
  68. HRESULT CAddToDfs::get_JPName
  69. (
  70. BSTR *o_bstrJPName
  71. )
  72. {
  73. if (!o_bstrJPName)
  74. return(E_INVALIDARG);
  75. *o_bstrJPName = SysAllocString(m_bstrJPName);
  76. if (!*o_bstrJPName)
  77. return(E_OUTOFMEMORY);
  78. return(S_OK);
  79. }
  80. HRESULT CAddToDfs::get_NetPath
  81. (
  82. BSTR *o_bstrNetPath
  83. )
  84. {
  85. /*++
  86. Routine Description:
  87. Returns the complete share path typed in by the user in the edit box.
  88. */
  89. if (!o_bstrNetPath)
  90. return(E_INVALIDARG);
  91. *o_bstrNetPath = SysAllocString(m_bstrNetPath);
  92. if (!*o_bstrNetPath)
  93. return(E_OUTOFMEMORY);
  94. return(S_OK);
  95. }
  96. HRESULT CAddToDfs::get_Server
  97. (
  98. BSTR *o_bstrServer
  99. )
  100. {
  101. /*++
  102. Routine Description:
  103. Returns the server component of the share path.
  104. */
  105. if (!o_bstrServer)
  106. return(E_INVALIDARG);
  107. *o_bstrServer = SysAllocString(m_bstrServer);
  108. if (!*o_bstrServer)
  109. return(E_OUTOFMEMORY);
  110. return(S_OK);
  111. }
  112. HRESULT CAddToDfs::get_Share
  113. (
  114. BSTR *o_bstrShare
  115. )
  116. {
  117. /*++
  118. Routine Description:
  119. Returns the share component of the share path.
  120. */
  121. if (!o_bstrShare)
  122. return(E_INVALIDARG);
  123. *o_bstrShare = SysAllocString(m_bstrShare);
  124. if (!*o_bstrShare)
  125. return(E_OUTOFMEMORY);
  126. return(S_OK);
  127. }
  128. HRESULT CAddToDfs::get_Time
  129. (
  130. long *o_plTime
  131. )
  132. {
  133. if (!o_plTime)
  134. return(E_INVALIDARG);
  135. *o_plTime = m_lTime;
  136. return(S_OK);
  137. }
  138. extern WNDPROC g_fnOldEditCtrlProc;
  139. LRESULT CAddToDfs::OnInitDialog
  140. (
  141. UINT uMsg,
  142. WPARAM wParam,
  143. LPARAM lParam,
  144. BOOL& bHandled
  145. )
  146. {
  147. /*++
  148. Routine Description:
  149. Performs the dialog initialization.
  150. Arguments:
  151. As sent by Dialog Handler.
  152. Return value:
  153. */
  154. m_bstrEntryPath.Empty();
  155. // Format the Parent enrty path and also display it in the static text.
  156. m_bstrParentPath += _T("\\");
  157. SetDlgItemText(IDC_EDIT_ADDLINK_DFSLINK_PATH, m_bstrParentPath);
  158. // Set the default time out value after getting it from the string resource.
  159. ::SendMessage(GetDlgItem(IDC_EDITTIME), EM_LIMITTEXT, 10, 0);
  160. TCHAR szTime[16];
  161. _stprintf(szTime, _T("%u"), m_lTime);
  162. SetDlgItemText(IDC_EDITTIME, szTime);
  163. g_fnOldEditCtrlProc = reinterpret_cast<WNDPROC>(
  164. ::SetWindowLongPtr(
  165. GetDlgItem(IDC_EDITTIME),
  166. GWLP_WNDPROC,
  167. reinterpret_cast<LONG_PTR>(NoPasteEditCtrlProc)));
  168. ::SendMessage(GetDlgItem(IDC_EDITNETPATH), EM_LIMITTEXT, MAX_PATH, 0);
  169. ::SendMessage(GetDlgItem(IDC_EDITCOMMENT), EM_LIMITTEXT, MAXCOMMENTSZ, 0);
  170. // Set the previous contents.
  171. SetDlgItemText(IDC_EDITNETPATH, m_bstrNetPath);
  172. SetDlgItemText(IDC_EDITCOMMENT, m_bstrComment);
  173. return TRUE; // Let the system set the focus
  174. }
  175. /*++
  176. This function is called when a user clicks the ? in the top right of a property sheet
  177. and then clciks a control, or when they hit F1 in a control.
  178. --*/
  179. LRESULT CAddToDfs::OnCtxHelp(
  180. IN UINT i_uMsg,
  181. IN WPARAM i_wParam,
  182. IN LPARAM i_lParam,
  183. IN OUT BOOL& io_bHandled
  184. )
  185. {
  186. LPHELPINFO lphi = (LPHELPINFO) i_lParam;
  187. if (!lphi || lphi->iContextType != HELPINFO_WINDOW || lphi->iCtrlId < 0)
  188. return FALSE;
  189. ::WinHelp((HWND)(lphi->hItemHandle),
  190. DFS_CTX_HELP_FILE,
  191. HELP_WM_HELP,
  192. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_ADDTODFS);
  193. return TRUE;
  194. }
  195. /*++
  196. This function handles "What's This" help when a user right clicks the control
  197. --*/
  198. LRESULT CAddToDfs::OnCtxMenuHelp(
  199. IN UINT i_uMsg,
  200. IN WPARAM i_wParam,
  201. IN LPARAM i_lParam,
  202. IN OUT BOOL& io_bHandled
  203. )
  204. {
  205. ::WinHelp((HWND)i_wParam,
  206. DFS_CTX_HELP_FILE,
  207. HELP_CONTEXTMENU,
  208. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_ADDTODFS);
  209. return TRUE;
  210. }
  211. LRESULT CAddToDfs::OnOK
  212. (
  213. WORD wNotifyCode,
  214. WORD wID,
  215. HWND hWndCtl,
  216. BOOL& bHandled
  217. )
  218. {
  219. BOOL bValidInput = FALSE;
  220. int idControl = 0;
  221. int idString = 0;
  222. HRESULT hr = S_OK;
  223. do {
  224. CWaitCursor wait;
  225. DWORD dwTextLength = 0;
  226. // Validate IDC_EDITCOMMENT
  227. m_bstrComment.Empty();
  228. hr = GetInputText(GetDlgItem(IDC_EDITCOMMENT), &m_bstrComment, &dwTextLength);
  229. if (FAILED(hr))
  230. break;
  231. if (0 == dwTextLength)
  232. m_bstrComment = _T("");
  233. // Validate IDC_EDITCHLDNODE
  234. idControl = IDC_EDITCHLDNODE;
  235. m_bstrJPName.Empty();
  236. hr = GetInputText(GetDlgItem(IDC_EDITCHLDNODE), &m_bstrJPName, &dwTextLength);
  237. if (FAILED(hr))
  238. break;
  239. if (0 == dwTextLength)
  240. {
  241. idString = IDS_MSG_EMPTY_FIELD;
  242. break;
  243. }
  244. m_bstrEntryPath = m_bstrParentPath;
  245. m_bstrEntryPath += m_bstrJPName;
  246. hr = CheckUNCPath(m_bstrEntryPath);
  247. if (S_OK != hr)
  248. {
  249. hr = S_FALSE;
  250. idString = IDS_INVALID_LINKNAME;
  251. break;
  252. }
  253. // Validate IDC_EDITNETPATH
  254. idControl = IDC_EDITNETPATH;
  255. m_bstrNetPath.Empty();
  256. hr = GetInputText(GetDlgItem(IDC_EDITNETPATH), &m_bstrNetPath, &dwTextLength);
  257. if (FAILED(hr))
  258. break;
  259. if (0 == dwTextLength)
  260. {
  261. idString = IDS_MSG_EMPTY_FIELD;
  262. break;
  263. }
  264. m_bstrServer.Empty();
  265. m_bstrShare.Empty();
  266. if (!ValidateNetPath(m_bstrNetPath, &m_bstrServer, &m_bstrShare))
  267. break;
  268. // Validate IDC_EDITTIME
  269. idControl = IDC_EDITTIME;
  270. CComBSTR bstrTemp;
  271. hr = GetInputText(GetDlgItem(IDC_EDITTIME), &bstrTemp, &dwTextLength);
  272. if (FAILED(hr))
  273. break;
  274. ULONG ulTimeout = 0;
  275. if (0 == dwTextLength || !ValidateTimeout(bstrTemp, &ulTimeout))
  276. {
  277. idString = IDS_MSG_TIMEOUT_INVALIDRANGE;
  278. break;
  279. }
  280. m_lTime = ulTimeout;
  281. bValidInput = TRUE;
  282. } while (0);
  283. if (FAILED(hr))
  284. {
  285. DisplayMessageBoxForHR(hr);
  286. ::SetFocus(GetDlgItem(idControl));
  287. return FALSE;
  288. } else if (bValidInput)
  289. {
  290. EndDialog(S_OK);
  291. return TRUE;
  292. } else
  293. {
  294. if (idString)
  295. DisplayMessageBoxWithOK(idString);
  296. ::SetFocus(GetDlgItem(idControl));
  297. return FALSE;
  298. }
  299. }
  300. LRESULT CAddToDfs::OnCancel
  301. (
  302. WORD wNotifyCode,
  303. WORD wID,
  304. HWND hWndCtl,
  305. BOOL& bHandled
  306. )
  307. {
  308. EndDialog(S_FALSE);
  309. return(true);
  310. }
  311. LRESULT CAddToDfs::OnNetBrowse
  312. (
  313. WORD wNotifyCode,
  314. WORD wID,
  315. HWND hWndCtl,
  316. BOOL& bHandled
  317. )
  318. {
  319. CComBSTR bstrPath;
  320. HRESULT hr = BrowseNetworkPath(hWndCtl, &bstrPath);
  321. if (S_OK == hr)
  322. {
  323. SetDlgItemText(IDC_EDITNETPATH, bstrPath);
  324. ::SetFocus(GetDlgItem(IDC_EDITCOMMENT));
  325. }
  326. if (S_FALSE == hr)
  327. ::SetFocus(GetDlgItem(IDC_EDITNETPATH));
  328. return (SUCCEEDED(hr));
  329. }
  330. LRESULT
  331. CAddToDfs::OnChangeDfsLink(
  332. WORD wNotifyCode,
  333. WORD wID,
  334. HWND hWndCtl,
  335. BOOL& bHandled)
  336. {
  337. CComBSTR bstrDfsLinkName;
  338. DWORD dwTextLength = 0;
  339. (void)GetInputText(GetDlgItem(IDC_EDITCHLDNODE), &bstrDfsLinkName, &dwTextLength);
  340. if ((BSTR)bstrDfsLinkName)
  341. {
  342. CComBSTR bstrFullPath = m_bstrParentPath;
  343. bstrFullPath += bstrDfsLinkName;
  344. SetDlgItemText(IDC_EDIT_ADDLINK_DFSLINK_PATH, bstrFullPath);
  345. ::SendMessage(GetDlgItem(IDC_EDIT_ADDLINK_DFSLINK_PATH), EM_SETSEL, 0, (LPARAM)-1);
  346. ::SendMessage(GetDlgItem(IDC_EDIT_ADDLINK_DFSLINK_PATH), EM_SETSEL, (WPARAM)-1, 0);
  347. ::SendMessage(GetDlgItem(IDC_EDIT_ADDLINK_DFSLINK_PATH), EM_SCROLLCARET, 0, 0);
  348. }
  349. return TRUE;
  350. }