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.

608 lines
15 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1995.
  5. //
  6. // File: pages.cxx
  7. //
  8. // Contents: property pages for provider, domain/workgroup, server, share
  9. //
  10. // History: 26-Sep-95 BruceFo Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "headers.hxx"
  14. #pragma hdrstop
  15. #include "resource.h"
  16. #include "helpids.h"
  17. #include "ext.hxx"
  18. #include "pages.hxx"
  19. #include "util.hxx"
  20. ////////////////////////////////////////////////////////////////////////////
  21. //
  22. // This is the minimum version number necessary to
  23. // actually display a version number. If we get a
  24. // machine with a major version number less that this
  25. // value, we don't display the version number.
  26. //
  27. #define MIN_DISPLAY_VER 2
  28. ////////////////////////////////////////////////////////////////////////////
  29. //+-------------------------------------------------------------------------
  30. //
  31. // Method: CPage::PageCallback, static public
  32. //
  33. // Synopsis:
  34. //
  35. //--------------------------------------------------------------------------
  36. UINT CALLBACK
  37. CPage::PageCallback(
  38. IN HWND hwnd,
  39. IN UINT uMsg,
  40. IN LPPROPSHEETPAGE ppsp
  41. )
  42. {
  43. switch (uMsg)
  44. {
  45. case PSPCB_CREATE:
  46. return 1; // allow creation
  47. case PSPCB_RELEASE:
  48. {
  49. CPage* pThis = (CPage*)ppsp->lParam;
  50. delete pThis; // do this LAST!
  51. return 0; // ignored
  52. }
  53. default:
  54. appDebugOut((DEB_ERROR, "CPage::PageCallback, unknown page callback message %d\n", uMsg));
  55. return 0;
  56. } // end switch
  57. }
  58. //+-------------------------------------------------------------------------
  59. //
  60. // Method: CPage::DlgProcPage, static public
  61. //
  62. // Synopsis: Dialog Procedure for all CPage
  63. //
  64. //--------------------------------------------------------------------------
  65. BOOL CALLBACK
  66. CPage::DlgProcPage(
  67. IN HWND hwnd,
  68. IN UINT msg,
  69. IN WPARAM wParam,
  70. IN LPARAM lParam
  71. )
  72. {
  73. CPage* pThis = NULL;
  74. if (msg==WM_INITDIALOG)
  75. {
  76. PROPSHEETPAGE* psp = (PROPSHEETPAGE*)lParam;
  77. pThis = (CPage*)psp->lParam;
  78. SetWindowLong(hwnd,GWL_USERDATA,(LPARAM)pThis);
  79. }
  80. else
  81. {
  82. pThis = (CPage*) GetWindowLong(hwnd,GWL_USERDATA);
  83. }
  84. if (pThis != NULL)
  85. {
  86. return pThis->_PageProc(hwnd,msg,wParam,lParam);
  87. }
  88. else
  89. {
  90. return FALSE;
  91. }
  92. }
  93. //+--------------------------------------------------------------------------
  94. //
  95. // Method: CPage::CPage, public
  96. //
  97. // Synopsis: Constructor
  98. //
  99. //---------------------------------------------------------------------------
  100. CPage::CPage(
  101. IN CNetObj* pNetObj
  102. )
  103. :
  104. _pNetObj(pNetObj)
  105. {
  106. INIT_SIG(CPage);
  107. if (NULL != _pNetObj)
  108. {
  109. //
  110. // We need to addref this because we are using member variable
  111. // of this class.
  112. //
  113. _pNetObj->AddRef();
  114. }
  115. }
  116. //+--------------------------------------------------------------------------
  117. //
  118. // Method: CPage::~CPage, public
  119. //
  120. // Synopsis: Destructor
  121. //
  122. //---------------------------------------------------------------------------
  123. CPage::~CPage()
  124. {
  125. CHECK_SIG(CPage);
  126. if (NULL != _pNetObj)
  127. {
  128. _pNetObj->Release();
  129. }
  130. }
  131. //+-------------------------------------------------------------------------
  132. //
  133. // Method: CPage::InitInstance, public
  134. //
  135. // Synopsis: Part II of the constuctor process
  136. //
  137. // Notes: We don't want to handle any errors in constuctor, so this
  138. // method is necessary for the second phase error detection.
  139. //
  140. //--------------------------------------------------------------------------
  141. HRESULT
  142. CPage::InitInstance(
  143. VOID
  144. )
  145. {
  146. CHECK_SIG(CPage);
  147. appDebugOut((DEB_ITRACE, "CPage::InitInstance\n"));
  148. return S_OK;
  149. }
  150. //+-------------------------------------------------------------------------
  151. //
  152. // Method: CPage::_PageProc, private
  153. //
  154. // Synopsis: Dialog Procedure for this object
  155. //
  156. //--------------------------------------------------------------------------
  157. BOOL
  158. CPage::_PageProc(
  159. IN HWND hwnd,
  160. IN UINT msg,
  161. IN WPARAM wParam,
  162. IN LPARAM lParam
  163. )
  164. {
  165. CHECK_SIG(CPage);
  166. static DWORD aHelpIds[] =
  167. {
  168. IDC_NETWORK, IDH_NET_NETWORK,
  169. IDC_NETWORK_ICON, IDH_NET_NETWORK,
  170. IDC_SERVER, IDH_NET_SERVER,
  171. IDC_SERVER_ICON, IDH_NET_SERVER,
  172. IDC_SERVER_TEXT, IDH_NET_SERVER,
  173. IDC_COMMENT, IDH_NET_COMMENT,
  174. IDC_COMMENT_TEXT, IDH_NET_COMMENT,
  175. IDC_WORKGROUP_OR_DOMAIN, IDH_NET_WORKGROUP_OR_DOMAIN_NAME,
  176. IDC_WORKGROUP_OR_DOMAIN_NAME, IDH_NET_WORKGROUP_OR_DOMAIN_NAME,
  177. IDC_WORKGROUP_OR_DOMAIN_NAME_2_ICON, IDH_NET_WORKGROUP_OR_DOMAIN_NAME_2,
  178. IDC_WORKGROUP_OR_DOMAIN_NAME_2, IDH_NET_WORKGROUP_OR_DOMAIN_NAME_2,
  179. IDC_TYPE, IDH_NET_TYPE,
  180. IDC_TYPE_TEXT, IDH_NET_TYPE,
  181. IDC_SHARE, IDH_NET_SHARE,
  182. IDC_SHARE_ICON, IDH_NET_SHARE,
  183. IDC_WRKGRP_TYPE, IDH_NET_WRKGRP_TYPE,
  184. IDC_WRKGRP_TYPE_TEXT, IDH_NET_WRKGRP_TYPE,
  185. 0,0
  186. };
  187. switch (msg)
  188. {
  189. case WM_INITDIALOG:
  190. _hwndPage = hwnd;
  191. return _OnInitDialog(hwnd, (HWND)wParam, lParam);
  192. case WM_NOTIFY:
  193. return _OnNotify(hwnd, (int)wParam, (LPNMHDR)lParam);
  194. case WM_HELP:
  195. {
  196. LPHELPINFO lphi = (LPHELPINFO)lParam;
  197. if (lphi->iContextType == HELPINFO_WINDOW) // a control
  198. {
  199. WCHAR szHelp[50];
  200. LoadString(g_hInstance, IDS_HELPFILENAME, szHelp, ARRAYLEN(szHelp));
  201. WinHelp(
  202. (HWND)lphi->hItemHandle,
  203. szHelp,
  204. HELP_WM_HELP,
  205. (DWORD)(LPVOID)aHelpIds);
  206. }
  207. break;
  208. }
  209. case WM_CONTEXTMENU:
  210. {
  211. WCHAR szHelp[50];
  212. LoadString(g_hInstance, IDS_HELPFILENAME, szHelp, ARRAYLEN(szHelp));
  213. WinHelp(
  214. (HWND)wParam,
  215. szHelp,
  216. HELP_CONTEXTMENU,
  217. (DWORD)(LPVOID)aHelpIds);
  218. break;
  219. }
  220. } // end switch (msg)
  221. return FALSE;
  222. }
  223. //+-------------------------------------------------------------------------
  224. //
  225. // Method: CPage::_OnInitDialog, private
  226. //
  227. // Synopsis: WM_INITDIALOG handler
  228. //
  229. //--------------------------------------------------------------------------
  230. BOOL
  231. CPage::_OnInitDialog(
  232. IN HWND hwnd,
  233. IN HWND hwndFocus,
  234. IN LPARAM lInitParam
  235. )
  236. {
  237. CHECK_SIG(CPage);
  238. appDebugOut((DEB_ITRACE, "_OnInitDialog\n"));
  239. appAssert(NULL != _pNetObj);
  240. LPNETRESOURCE pnr = (LPNETRESOURCE)_pNetObj->_bufNetResource;
  241. appAssert(NULL != pnr);
  242. if (RESOURCEDISPLAYTYPE_NETWORK == pnr->dwDisplayType)
  243. {
  244. return _OnInitNetwork(hwnd, pnr);
  245. }
  246. else if (RESOURCEDISPLAYTYPE_DOMAIN == pnr->dwDisplayType)
  247. {
  248. return _OnInitDomain(hwnd, pnr);
  249. }
  250. else if (RESOURCEDISPLAYTYPE_SERVER == pnr->dwDisplayType)
  251. {
  252. return _OnInitServerOrShare(hwnd, pnr, TRUE);
  253. }
  254. else if (RESOURCEDISPLAYTYPE_SHARE == pnr->dwDisplayType)
  255. {
  256. return _OnInitServerOrShare(hwnd, pnr, FALSE);
  257. }
  258. else
  259. {
  260. appAssert(!"CNetObj::AddPages. Unknown net resource type!\n");
  261. return TRUE;
  262. }
  263. }
  264. //+-------------------------------------------------------------------------
  265. //
  266. // Method: CPage::_OnInitNetwork, private
  267. //
  268. // Synopsis: WM_INITDIALOG handler
  269. //
  270. //--------------------------------------------------------------------------
  271. BOOL
  272. CPage::_OnInitNetwork(
  273. IN HWND hwnd,
  274. IN LPNETRESOURCE pnr
  275. )
  276. {
  277. CHECK_SIG(CPage);
  278. appAssert(NULL != pnr);
  279. SetDlgItemText(hwnd, IDC_NETWORK, pnr->lpProvider);
  280. return TRUE;
  281. }
  282. //+-------------------------------------------------------------------------
  283. //
  284. // Method: CPage::_OnInitDomain, private
  285. //
  286. // Synopsis: WM_INITDIALOG handler
  287. //
  288. //--------------------------------------------------------------------------
  289. BOOL
  290. CPage::_OnInitDomain(
  291. IN HWND hwnd,
  292. LPNETRESOURCE pnr
  293. )
  294. {
  295. CHECK_SIG(CPage);
  296. appAssert(NULL != pnr);
  297. SetDlgItemText(hwnd, IDC_WORKGROUP_OR_DOMAIN_NAME_2, pnr->lpRemoteName);
  298. SetDlgItemText(hwnd, IDC_WRKGRP_TYPE, pnr->lpProvider);
  299. return TRUE;
  300. }
  301. //+-------------------------------------------------------------------------
  302. //
  303. // Method: CPage::_OnInitServerOrShare, private
  304. //
  305. // Synopsis: WM_INITDIALOG handler for Server and Share objects
  306. //
  307. //--------------------------------------------------------------------------
  308. BOOL
  309. CPage::_OnInitServerOrShare(
  310. IN HWND hwnd,
  311. IN LPNETRESOURCE pnr,
  312. IN BOOL fServer // TRUE == server, FALSE == share
  313. )
  314. {
  315. CHECK_SIG(CPage);
  316. appAssert(NULL != pnr);
  317. CWaitCursor wait;
  318. NET_API_STATUS err;
  319. LPTSTR pszRealServerName = pnr->lpRemoteName;
  320. appAssert(NULL != pszRealServerName);
  321. // Figure out server name without UNC prefix
  322. if (pszRealServerName[0] == TEXT('\\') && pszRealServerName[1] == TEXT('\\'))
  323. {
  324. pszRealServerName += 2;
  325. }
  326. if (!fServer)
  327. {
  328. // Get share name
  329. LPTSTR pszShareName = wcschr(pszRealServerName, TEXT('\\'));
  330. appAssert(NULL != pszShareName);
  331. *pszShareName++ = TEXT('\0'); // NOTE: NULL-terminating server name
  332. SetDlgItemText(hwnd, IDC_SHARE, pszShareName);
  333. }
  334. SetDlgItemText(hwnd, IDC_SERVER, pszRealServerName);
  335. // Get server information
  336. PSERVER_INFO_101 pServerInfo = NULL;
  337. err = NetServerGetInfo(pnr->lpRemoteName, 101, (LPBYTE*)&pServerInfo);
  338. if (NERR_Success != err)
  339. {
  340. MyErrorDialog(hwnd, MessageFromError(err), pszRealServerName);
  341. return TRUE;
  342. }
  343. // NOTE: I now have a pServerInfo to delete
  344. appAssert(NULL != pServerInfo);
  345. if (fServer)
  346. {
  347. if (NULL != pServerInfo->sv101_comment)
  348. {
  349. SetDlgItemText(hwnd, IDC_COMMENT, pServerInfo->sv101_comment);
  350. }
  351. }
  352. _SetServerType(hwnd, IDC_TYPE, pServerInfo);
  353. DWORD svtype = pServerInfo->sv101_type; // save type for later use
  354. NetApiBufferFree(pServerInfo); // get rid of it so we don't have to worry about it
  355. UINT idLogonType = IDS_LOGON_WORKGROUP;
  356. if (svtype & SV_TYPE_NT)
  357. {
  358. // It's an NT server. See if it is in a workgroup or a domain.
  359. LPWSTR pszDomainName;
  360. BOOL bIsWorkgroupName;
  361. err = MyNetpGetDomainNameEx(pnr->lpRemoteName, &pszDomainName, &bIsWorkgroupName);
  362. if (err != NERR_Success)
  363. {
  364. MyErrorDialog(hwnd, MessageFromError(err), pszRealServerName);
  365. return TRUE;
  366. }
  367. SetDlgItemText(hwnd, IDC_WORKGROUP_OR_DOMAIN_NAME, pszDomainName);
  368. NetApiBufferFree(pszDomainName);
  369. if (!bIsWorkgroupName)
  370. {
  371. idLogonType = IDS_LOGON_DOMAIN;
  372. }
  373. }
  374. else
  375. {
  376. // It's not an NT server, so assume it's a workgroup.
  377. PWKSTA_INFO_100 pWorkstationInfo = NULL;
  378. err = NetWkstaGetInfo(pnr->lpRemoteName, 100, (LPBYTE*)&pWorkstationInfo);
  379. if (NERR_Success != err)
  380. {
  381. MyErrorDialog(hwnd, MessageFromError(err), pszRealServerName);
  382. return TRUE;
  383. }
  384. appAssert(NULL != pWorkstationInfo);
  385. if (NULL != pWorkstationInfo->wki100_langroup)
  386. {
  387. SetDlgItemText(hwnd, IDC_WORKGROUP_OR_DOMAIN_NAME, pWorkstationInfo->wki100_langroup);
  388. }
  389. NetApiBufferFree(pWorkstationInfo);
  390. }
  391. WCHAR szLogonType[80];
  392. LoadString(g_hInstance, idLogonType, szLogonType, ARRAYLEN(szLogonType));
  393. SetDlgItemText(hwnd, IDC_WORKGROUP_OR_DOMAIN, szLogonType);
  394. return TRUE;
  395. }
  396. //+-------------------------------------------------------------------------
  397. //
  398. // Method: CPage::_OnNotify, private
  399. //
  400. // Synopsis: WM_NOTIFY handler
  401. //
  402. //--------------------------------------------------------------------------
  403. BOOL
  404. CPage::_OnNotify(
  405. IN HWND hwnd,
  406. IN int idCtrl,
  407. IN LPNMHDR phdr
  408. )
  409. {
  410. CHECK_SIG(CPage);
  411. switch (phdr->code)
  412. {
  413. case PSN_APPLY:
  414. case PSN_RESET: // cancel
  415. SetWindowLong(hwnd, DWL_MSGRESULT, FALSE); // go away
  416. return TRUE;
  417. case PSN_KILLACTIVE: // change to another page
  418. SetWindowLong(hwnd, DWL_MSGRESULT, PSNRET_NOERROR);
  419. return FALSE;
  420. case PSN_SETACTIVE:
  421. case PSN_QUERYCANCEL:
  422. return FALSE;
  423. } // end switch (phdr->code)
  424. return FALSE;
  425. }
  426. //+-------------------------------------------------------------------------
  427. //
  428. // Method: CPage::_SetServerType, private
  429. //
  430. // Synopsis: Sets a server type control
  431. //
  432. //--------------------------------------------------------------------------
  433. VOID
  434. CPage::_SetServerType(
  435. HWND hwnd,
  436. int idControl,
  437. PSERVER_INFO_101 pinfo
  438. )
  439. {
  440. UINT idType, idRole;
  441. HRESULT msgFormat;
  442. //
  443. // Determine the server's type (NT, LM, etc) and role.
  444. //
  445. DWORD type = pinfo->sv101_type;
  446. if (type & SV_TYPE_NT)
  447. {
  448. idType = IDS_SERVER_TYPE_WINNT;
  449. }
  450. else
  451. if (type & SV_TYPE_WINDOWS)
  452. {
  453. idType = IDS_SERVER_TYPE_WINDOWS95;
  454. }
  455. else
  456. if (type & SV_TYPE_WFW)
  457. {
  458. idType = IDS_SERVER_TYPE_WFW;
  459. }
  460. else
  461. {
  462. idType = IDS_SERVER_TYPE_LANMAN;
  463. }
  464. if (type & SV_TYPE_DOMAIN_CTRL)
  465. {
  466. idRole = IDS_ROLE_PRIMARY;
  467. }
  468. else
  469. if (type & SV_TYPE_DOMAIN_BAKCTRL)
  470. {
  471. idRole = IDS_ROLE_BACKUP;
  472. }
  473. else
  474. if (type & SV_TYPE_SERVER_NT)
  475. {
  476. idRole = IDS_ROLE_SERVER;
  477. }
  478. else
  479. {
  480. idRole = IDS_ROLE_WKSTA;
  481. }
  482. UINT verMajor = pinfo->sv101_version_major & MAJOR_VERSION_MASK;
  483. UINT verMinor = pinfo->sv101_version_minor;
  484. msgFormat = (verMajor < MIN_DISPLAY_VER || (type & SV_TYPE_WINDOWS))
  485. ? MSG_TYPE_FORMAT_UNKNOWN
  486. : MSG_TYPE_FORMAT
  487. ;
  488. WCHAR szType[80];
  489. LoadString(g_hInstance, idType, szType, ARRAYLEN(szType));
  490. WCHAR szRole[80];
  491. LoadString(g_hInstance, idRole, szRole, ARRAYLEN(szRole));
  492. DWORD aInserts[4];
  493. aInserts[0] = (DWORD)szType;
  494. aInserts[1] = verMajor;
  495. aInserts[2] = verMinor;
  496. aInserts[3] = (DWORD)szRole;
  497. WCHAR szBuffer[256];
  498. DWORD dwReturn = FormatMessage(
  499. FORMAT_MESSAGE_FROM_HMODULE
  500. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  501. g_hInstance,
  502. msgFormat,
  503. LANG_SYSTEM_DEFAULT,
  504. szBuffer,
  505. ARRAYLEN(szBuffer),
  506. (va_list*)aInserts);
  507. if (0 == dwReturn) // couldn't find message
  508. {
  509. appDebugOut((DEB_IERROR,
  510. "FormatMessage failed, 0x%08lx\n",
  511. GetLastError()));
  512. szBuffer[0] = TEXT('\0');
  513. }
  514. SetDlgItemText(hwnd, idControl, szBuffer);
  515. }