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.

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