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.

786 lines
22 KiB

  1. //-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: T C P W I N S . C P P
  7. //
  8. // Contents: CTcpWinsPage implementation
  9. //
  10. // Notes: The "WINS Address" page
  11. //
  12. // Author: tongl 12 Nov 1997
  13. //
  14. //-----------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "ncatlui.h"
  18. #include "ncstl.h"
  19. #include "ncui.h"
  20. #include "ncmisc.h"
  21. #include "tcpconst.h"
  22. #include "tcpipobj.h"
  23. #include "resource.h"
  24. #include "tcpmacro.h"
  25. #include "dlgaddr.h"
  26. #include "dlgwins.h"
  27. #include "tcpconst.h"
  28. #include "tcputil.h"
  29. #include "tcphelp.h"
  30. #define MAX_WINS_SERVER 12
  31. #define MAX_RAS_WINS_SERVER 2
  32. CTcpWinsPage::CTcpWinsPage( CTcpipcfg * ptcpip,
  33. CTcpAddrPage * pTcpAddrPage,
  34. ADAPTER_INFO * pAdapterDlg,
  35. GLOBAL_INFO * pGlbDlg,
  36. const DWORD * adwHelpIDs)
  37. {
  38. // Save everything passed to us
  39. Assert(ptcpip != NULL);
  40. m_ptcpip = ptcpip;
  41. Assert(pTcpAddrPage != NULL);
  42. m_pParentDlg = pTcpAddrPage;
  43. Assert(pAdapterDlg != NULL);
  44. m_pAdapterInfo = pAdapterDlg;
  45. Assert(pGlbDlg != NULL);
  46. m_pglb = pGlbDlg;
  47. m_adwHelpIDs = adwHelpIDs;
  48. // Initialize internal states
  49. m_fModified = FALSE;
  50. m_fLmhostsFileReset = FALSE;
  51. WCHAR* pch;
  52. // gives double NULL by default
  53. ZeroMemory(m_szFilter, sizeof(m_szFilter));
  54. ZeroMemory(&m_ofn, sizeof(m_ofn));
  55. wsprintfW(m_szFilter, L"%s|%s", (PCWSTR)SzLoadIds(IDS_COMMONDLG_TEXT), L"*.*");
  56. // replace '|' with NULL, required by common dialog
  57. pch = m_szFilter;
  58. while ((pch = wcschr(pch, '|')) != NULL)
  59. *pch++ = L'\0';
  60. m_ofn.lStructSize = sizeof(OPENFILENAME);
  61. m_ofn.hInstance = _Module.GetModuleInstance();
  62. m_ofn.lpstrFilter = m_szFilter;
  63. m_ofn.nFilterIndex = 1L;
  64. }
  65. LRESULT CTcpWinsPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  66. LPARAM lParam, BOOL& fHandled)
  67. {
  68. // Initialize the Wins address listbox
  69. m_fEditState = FALSE;
  70. // Cache hwnds
  71. m_hServers.m_hList = GetDlgItem(IDC_WINS_SERVER_LIST);
  72. m_hServers.m_hAdd = GetDlgItem(IDC_WINS_ADD);
  73. m_hServers.m_hEdit = GetDlgItem(IDC_WINS_EDIT);
  74. m_hServers.m_hRemove = GetDlgItem(IDC_WINS_REMOVE);
  75. m_hServers.m_hUp = GetDlgItem(IDC_WINS_UP);
  76. m_hServers.m_hDown = GetDlgItem(IDC_WINS_DOWN);
  77. // Set the up\down arrow icons
  78. SendDlgItemMessage(IDC_WINS_UP, BM_SETIMAGE, IMAGE_ICON,
  79. reinterpret_cast<LPARAM>(g_hiconUpArrow));
  80. SendDlgItemMessage(IDC_WINS_DOWN, BM_SETIMAGE, IMAGE_ICON,
  81. reinterpret_cast<LPARAM>(g_hiconDownArrow));
  82. // Get the Service address Add and Edit button Text and remove ellipse
  83. WCHAR szAddServer[16];
  84. GetDlgItemText(IDC_WINS_ADD, szAddServer, celems(szAddServer));
  85. szAddServer[lstrlenW(szAddServer) - c_cchRemoveCharatersFromEditOrAddButton] = 0;
  86. m_strAddServer = szAddServer;
  87. // Initialize controls on this page
  88. // WINS server list box
  89. int nResult= LB_ERR;
  90. for(VSTR_ITER iterWinsServer = m_pAdapterInfo->m_vstrWinsServerList.begin() ;
  91. iterWinsServer != m_pAdapterInfo->m_vstrWinsServerList.end() ;
  92. ++iterWinsServer)
  93. {
  94. nResult = Tcp_ListBox_InsertString(m_hServers.m_hList, -1,
  95. (*iterWinsServer)->c_str());
  96. }
  97. // set slection to first item
  98. if (nResult >= 0)
  99. {
  100. Tcp_ListBox_SetCurSel(m_hServers.m_hList, 0);
  101. }
  102. SetButtons(m_hServers,
  103. (m_pAdapterInfo->m_fIsRasFakeAdapter) ? MAX_RAS_WINS_SERVER : MAX_WINS_SERVER);
  104. // Enable LMHosts lookup ?
  105. CheckDlgButton(IDC_WINS_LOOKUP, m_pglb->m_fEnableLmHosts);
  106. ::EnableWindow(GetDlgItem(IDC_WINS_LMHOST), m_pglb->m_fEnableLmHosts);
  107. // Enable NetBt ?
  108. CheckDlgButton( IDC_RAD_ENABLE_NETBT,
  109. (c_dwEnableNetbios == m_pAdapterInfo->m_dwNetbiosOptions));
  110. CheckDlgButton( IDC_RAD_DISABLE_NETBT,
  111. (c_dwDisableNetbios == m_pAdapterInfo->m_dwNetbiosOptions));
  112. CheckDlgButton( IDC_RAD_UNSET_NETBT,
  113. (c_dwUnsetNetbios == m_pAdapterInfo->m_dwNetbiosOptions));
  114. if (m_pAdapterInfo->m_fIsRasFakeAdapter)
  115. {
  116. //if this is a ras connection, disable the default Netbt option since it
  117. //doesn't apply to RAS connections
  118. ::EnableWindow(GetDlgItem(IDC_RAD_UNSET_NETBT), FALSE);
  119. ::EnableWindow(GetDlgItem(IDC_STATIC_DEFALUT_NBT), FALSE);
  120. //this is a ras connection and a non-admin user, disable all the controls
  121. //for globl settings
  122. if (m_pParentDlg->m_fRasNotAdmin)
  123. {
  124. ::EnableWindow(GetDlgItem(IDC_WINS_STATIC_GLOBAL), FALSE);
  125. ::EnableWindow(GetDlgItem(IDC_WINS_LOOKUP), FALSE);
  126. ::EnableWindow(GetDlgItem(IDC_WINS_LMHOST), FALSE);
  127. }
  128. }
  129. return 0;
  130. }
  131. LRESULT CTcpWinsPage::OnContextMenu(UINT uMsg, WPARAM wParam,
  132. LPARAM lParam, BOOL& fHandled)
  133. {
  134. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  135. return 0;
  136. }
  137. LRESULT CTcpWinsPage::OnHelp(UINT uMsg, WPARAM wParam,
  138. LPARAM lParam, BOOL& fHandled)
  139. {
  140. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  141. Assert(lphi);
  142. if (HELPINFO_WINDOW == lphi->iContextType)
  143. {
  144. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  145. m_adwHelpIDs);
  146. }
  147. return 0;
  148. }
  149. LRESULT CTcpWinsPage::OnActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  150. {
  151. return 0;
  152. }
  153. LRESULT CTcpWinsPage::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  154. {
  155. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, 0);
  156. return 0;
  157. }
  158. LRESULT CTcpWinsPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  159. {
  160. BOOL nResult = PSNRET_NOERROR;
  161. // server list
  162. FreeCollectionAndItem(m_pAdapterInfo->m_vstrWinsServerList);
  163. int nCount = Tcp_ListBox_GetCount(m_hServers.m_hList);
  164. WCHAR szBuf[IP_LIMIT];
  165. for (int i = 0; i < nCount; i++)
  166. {
  167. #ifdef DBG
  168. int len = Tcp_ListBox_GetTextLen(m_hServers.m_hList, i);
  169. Assert(len != LB_ERR && len < IP_LIMIT);
  170. #endif
  171. Tcp_ListBox_GetText(m_hServers.m_hList, i, szBuf);
  172. m_pAdapterInfo->m_vstrWinsServerList.push_back(new tstring(szBuf));
  173. }
  174. // save checkbox states
  175. m_pglb->m_fEnableLmHosts = IsDlgButtonChecked(IDC_WINS_LOOKUP);
  176. // pass the info back to its parent dialog
  177. m_pParentDlg->m_fPropShtOk = TRUE;
  178. if(!m_pParentDlg->m_fPropShtModified)
  179. m_pParentDlg->m_fPropShtModified = IsModified();
  180. m_pParentDlg->m_fLmhostsFileReset = m_fLmhostsFileReset;
  181. // reset status
  182. SetModifiedTo(FALSE); // this page is no longer modified
  183. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, nResult);
  184. return nResult;
  185. }
  186. LRESULT CTcpWinsPage::OnCancel(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  187. {
  188. return 0;
  189. }
  190. LRESULT CTcpWinsPage::OnQueryCancel(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  191. {
  192. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, FALSE);
  193. return 0;
  194. }
  195. // WINS server related controls
  196. LRESULT CTcpWinsPage::OnAddServer(WORD wNotifyCode, WORD wID,
  197. HWND hWndCtl, BOOL& fHandled)
  198. {
  199. m_fEditState = FALSE;
  200. CWinsServerDialog DlgSrv(this, g_aHelpIDs_IDD_WINS_SERVER);
  201. if (DlgSrv.DoModal() == IDOK)
  202. {
  203. int nCount = Tcp_ListBox_GetCount(m_hServers.m_hList);
  204. int idx = Tcp_ListBox_InsertString(m_hServers.m_hList,
  205. -1,
  206. m_strNewIpAddress.c_str());
  207. Assert(idx>=0);
  208. if (idx >= 0)
  209. {
  210. PageModified();
  211. Tcp_ListBox_SetCurSel(m_hServers.m_hList, idx);
  212. SetButtons(m_hServers,
  213. (m_pAdapterInfo->m_fIsRasFakeAdapter) ? MAX_RAS_WINS_SERVER : MAX_WINS_SERVER);
  214. // empty strings, this removes the saved address from RemoveIP
  215. m_strNewIpAddress = L"";
  216. }
  217. }
  218. return 0;
  219. }
  220. LRESULT CTcpWinsPage::OnEditServer(WORD wNotifyCode, WORD wID,
  221. HWND hWndCtl, BOOL& fHandled)
  222. {
  223. m_fEditState = TRUE;
  224. Assert(Tcp_ListBox_GetCount(m_hServers.m_hList));
  225. int idx = Tcp_ListBox_GetCurSel(m_hServers.m_hList);
  226. Assert(idx >= 0);
  227. CWinsServerDialog DlgSrv(this, g_aHelpIDs_IDD_WINS_SERVER, idx);
  228. // save off the removed address and delete if from the listbox
  229. if (idx >= 0)
  230. {
  231. WCHAR buf[IP_LIMIT];
  232. Assert(Tcp_ListBox_GetTextLen(m_hServers.m_hList, idx) < celems(buf));
  233. Tcp_ListBox_GetText(m_hServers.m_hList, idx, buf);
  234. m_strNewIpAddress = buf; // used by dialog to display what to edit
  235. if (DlgSrv.DoModal() == IDOK)
  236. {
  237. // replace the item in the listview with the new information
  238. Tcp_ListBox_DeleteString(m_hServers.m_hList, idx);
  239. PageModified();
  240. m_strMovingEntry = m_strNewIpAddress;
  241. ListBoxInsertAfter(m_hServers.m_hList, idx, m_strMovingEntry.c_str());
  242. Tcp_ListBox_SetCurSel(m_hServers.m_hList, idx);
  243. m_strNewIpAddress = buf; // restore the original removed address
  244. }
  245. else
  246. {
  247. // empty strings, this removes the saved address from RemoveIP
  248. m_strNewIpAddress = L"";
  249. }
  250. }
  251. return 0;
  252. }
  253. LRESULT CTcpWinsPage::OnRemoveServer(WORD wNotifyCode, WORD wID,
  254. HWND hWndCtl, BOOL& fHandled)
  255. {
  256. int idx = Tcp_ListBox_GetCurSel(m_hServers.m_hList);
  257. Assert(idx >=0);
  258. if (idx >=0)
  259. {
  260. WCHAR buf[IP_LIMIT];
  261. Assert(Tcp_ListBox_GetTextLen(m_hServers.m_hList, idx) < celems(buf));
  262. Tcp_ListBox_GetText(m_hServers.m_hList, idx, buf);
  263. m_strNewIpAddress = buf;
  264. Tcp_ListBox_DeleteString(m_hServers.m_hList, idx);
  265. PageModified();
  266. // select a new item
  267. int nCount;
  268. if ((nCount = Tcp_ListBox_GetCount(m_hServers.m_hList)) != LB_ERR)
  269. {
  270. // select the previous item in the list
  271. if (idx)
  272. --idx;
  273. Tcp_ListBox_SetCurSel(m_hServers.m_hList, idx);
  274. }
  275. SetButtons(m_hServers,
  276. (m_pAdapterInfo->m_fIsRasFakeAdapter) ? MAX_RAS_WINS_SERVER : MAX_WINS_SERVER);
  277. }
  278. return 0;
  279. }
  280. LRESULT CTcpWinsPage::OnServerUp(WORD wNotifyCode, WORD wID,
  281. HWND hWndCtl, BOOL& fHandled)
  282. {
  283. Assert(m_hServers.m_hList);
  284. int nCount = Tcp_ListBox_GetCount(m_hServers.m_hList);
  285. Assert(nCount);
  286. int idx = Tcp_ListBox_GetCurSel(m_hServers.m_hList);
  287. Assert(idx != 0);
  288. if (ListBoxRemoveAt(m_hServers.m_hList, idx, &m_strMovingEntry) == FALSE)
  289. {
  290. Assert(FALSE);
  291. return 0;
  292. }
  293. --idx;
  294. PageModified();
  295. ListBoxInsertAfter(m_hServers.m_hList, idx, m_strMovingEntry.c_str());
  296. Tcp_ListBox_SetCurSel(m_hServers.m_hList, idx);
  297. SetButtons(m_hServers,
  298. (m_pAdapterInfo->m_fIsRasFakeAdapter) ? MAX_RAS_WINS_SERVER : MAX_WINS_SERVER);
  299. return 0;
  300. }
  301. LRESULT CTcpWinsPage::OnServerDown(WORD wNotifyCode, WORD wID,
  302. HWND hWndCtl, BOOL& fHandled)
  303. {
  304. Assert(m_hServers.m_hList);
  305. int nCount = Tcp_ListBox_GetCount(m_hServers.m_hList);
  306. Assert(nCount);
  307. int idx = Tcp_ListBox_GetCurSel(m_hServers.m_hList);
  308. --nCount;
  309. Assert(idx != nCount);
  310. if (ListBoxRemoveAt(m_hServers.m_hList, idx, &m_strMovingEntry) == FALSE)
  311. {
  312. Assert(FALSE);
  313. return 0;
  314. }
  315. ++idx;
  316. PageModified();
  317. ListBoxInsertAfter(m_hServers.m_hList, idx, m_strMovingEntry.c_str());
  318. Tcp_ListBox_SetCurSel(m_hServers.m_hList, idx);
  319. SetButtons(m_hServers,
  320. (m_pAdapterInfo->m_fIsRasFakeAdapter) ? MAX_RAS_WINS_SERVER : MAX_WINS_SERVER);
  321. return 0;
  322. }
  323. LRESULT CTcpWinsPage::OnServerList(WORD wNotifyCode, WORD wID,
  324. HWND hWndCtl, BOOL& fHandled)
  325. {
  326. switch (wNotifyCode)
  327. {
  328. case LBN_SELCHANGE:
  329. SetButtons(m_hServers,
  330. (m_pAdapterInfo->m_fIsRasFakeAdapter) ? MAX_RAS_WINS_SERVER : MAX_WINS_SERVER);
  331. break;
  332. default:
  333. break;
  334. }
  335. return 0;
  336. }
  337. LRESULT CTcpWinsPage::OnLookUp(WORD wNotifyCode, WORD wID,
  338. HWND hWndCtl, BOOL& fHandled)
  339. {
  340. ::EnableWindow(GetDlgItem(IDC_WINS_LMHOST),
  341. IsDlgButtonChecked(IDC_WINS_LOOKUP) == BST_CHECKED);
  342. PageModified();
  343. return 0;
  344. }
  345. LRESULT CTcpWinsPage::OnLMHost(WORD wNotifyCode, WORD wID,
  346. HWND hWndCtl, BOOL& fHandled)
  347. {
  348. WCHAR szFileName[MAX_PATH] = {NULL}; // initialize first character
  349. WCHAR szFileTitle[MAX_PATH] = {NULL}; // initialize first character
  350. // see if the Lookup check-box is checked
  351. Assert(IsDlgButtonChecked(IDC_WINS_LOOKUP) == BST_CHECKED);
  352. // add runtime info
  353. m_ofn.hwndOwner = m_hWnd;
  354. m_ofn.lpstrFile = szFileName;
  355. m_ofn.nMaxFile = celems(szFileName);
  356. m_ofn.lpstrFileTitle = szFileTitle;
  357. m_ofn.nMaxFileTitle = celems(szFileTitle);
  358. //if we are in GUI setup mode, explorer is not registered yet.
  359. //we need to use the old style of File Open dialog
  360. m_ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  361. if (!FInSystemSetup())
  362. {
  363. m_ofn.Flags |= OFN_EXPLORER;
  364. }
  365. else
  366. {
  367. m_ofn.Flags |= OFN_ENABLEHOOK;
  368. m_ofn.lpfnHook = HookProcOldStyle;
  369. }
  370. WCHAR szSysPath[MAX_PATH];
  371. WCHAR szSysPathBackup[MAX_PATH];
  372. BOOL fSysPathFound = (GetSystemDirectory(szSysPath, MAX_PATH) != 0);
  373. if (fSysPathFound && GetOpenFileName(&m_ofn)) // bring up common dialog
  374. {
  375. lstrcpyW(szSysPathBackup, szSysPath);
  376. wcscat(szSysPath, RGAS_LMHOSTS_PATH);
  377. // Backup the original lmhosts file if it hasn't been set dirty
  378. if (!m_ptcpip->FIsSecondMemoryLmhostsFileReset())
  379. {
  380. wcscat(szSysPathBackup, RGAS_LMHOSTS_PATH_BACKUP);
  381. WIN32_FIND_DATA FileData;
  382. if (FindFirstFile(szSysPath, &FileData) != INVALID_HANDLE_VALUE)
  383. {
  384. BOOL ret;
  385. // Copy lmhosts file to lmhosts.bak if it already exists
  386. ret = CopyFile(szSysPath, szSysPathBackup, FALSE);
  387. AssertSz(ret, "Failed to backup existing lmhosts file!");
  388. }
  389. }
  390. if (CopyFile(szFileName, szSysPath, FALSE) == 0) // overwrie lmhosts file
  391. {
  392. TraceError("CTcpWinsPage::OnLMHost", HrFromLastWin32Error());
  393. // cannot copy the file to the %system32%\drivers\etc dir
  394. NcMsgBox(::GetActiveWindow(),
  395. IDS_MSFT_TCP_TEXT,
  396. IDS_CANNOT_CREATE_LMHOST_ERROR,
  397. MB_APPLMODAL | MB_ICONSTOP | MB_OK,
  398. szSysPath);
  399. return 0;
  400. }
  401. else
  402. {
  403. // Set the flag so we can notify netbt of the change
  404. m_fLmhostsFileReset = TRUE;
  405. }
  406. TraceTag(ttidTcpip,"File Selected: %S", szSysPath);
  407. }
  408. else
  409. {
  410. // syspath failed
  411. if (fSysPathFound == FALSE)
  412. NcMsgBox(::GetActiveWindow(),
  413. IDS_MSFT_TCP_TEXT,
  414. IDS_WINS_SYSTEM_PATH,
  415. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  416. else if (szFileName[0] != NULL) // get open failed
  417. {
  418. NcMsgBox(::GetActiveWindow(),
  419. IDS_MSFT_TCP_TEXT,
  420. IDS_WINS_LMHOSTS_FAILED,
  421. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK,
  422. szSysPath);
  423. }
  424. }
  425. return 0;
  426. }
  427. LRESULT CTcpWinsPage::OnEnableNetbios(WORD wNotifyCode, WORD wID,
  428. HWND hWndCtl, BOOL& fHandled)
  429. {
  430. switch(wNotifyCode)
  431. {
  432. case BN_CLICKED:
  433. case BN_DOUBLECLICKED:
  434. if (m_pAdapterInfo->m_dwNetbiosOptions != c_dwEnableNetbios)
  435. {
  436. PageModified();
  437. // Update in memory structure
  438. m_pAdapterInfo->m_dwNetbiosOptions = c_dwEnableNetbios;
  439. }
  440. break;
  441. } // switch
  442. return 0;
  443. }
  444. LRESULT CTcpWinsPage::OnDisableNetbios(WORD wNotifyCode, WORD wID,
  445. HWND hWndCtl, BOOL& fHandled)
  446. {
  447. switch(wNotifyCode)
  448. {
  449. case BN_CLICKED:
  450. case BN_DOUBLECLICKED:
  451. if (m_pAdapterInfo->m_dwNetbiosOptions != c_dwDisableNetbios)
  452. {
  453. PageModified();
  454. // Update in memory structure
  455. m_pAdapterInfo->m_dwNetbiosOptions = c_dwDisableNetbios;
  456. }
  457. break;
  458. } // switch
  459. return 0;
  460. }
  461. LRESULT CTcpWinsPage::OnUnsetNetBios(WORD wNotifyCode, WORD wID,
  462. HWND hWndCtl, BOOL& fHandled)
  463. {
  464. switch(wNotifyCode)
  465. {
  466. case BN_CLICKED:
  467. case BN_DOUBLECLICKED:
  468. if (m_pAdapterInfo->m_dwNetbiosOptions != c_dwUnsetNetbios)
  469. {
  470. PageModified();
  471. // Update in memory structure
  472. m_pAdapterInfo->m_dwNetbiosOptions = c_dwUnsetNetbios;
  473. }
  474. break;
  475. } // switch
  476. return 0;
  477. }
  478. //
  479. // CWinsServerDialog
  480. //
  481. CWinsServerDialog::CWinsServerDialog(CTcpWinsPage * pTcpWinsPage,
  482. const DWORD* adwHelpIDs,
  483. int iIndex)
  484. {
  485. Assert(pTcpWinsPage);
  486. m_pParentDlg = pTcpWinsPage;
  487. m_hButton = 0;
  488. m_adwHelpIDs = adwHelpIDs;
  489. m_iIndex = iIndex;
  490. }
  491. LRESULT CWinsServerDialog::OnInitDialog(UINT uMsg, WPARAM wParam,
  492. LPARAM lParam, BOOL& fHandled)
  493. {
  494. // change the ok button to add if we are not editing
  495. if (m_pParentDlg->m_fEditState == FALSE)
  496. SetDlgItemText(IDOK, m_pParentDlg->m_strAddServer.c_str());
  497. m_ipAddress.Create(m_hWnd, IDC_WINS_CHANGE_SERVER);
  498. m_ipAddress.SetFieldRange(0, c_iIPADDR_FIELD_1_LOW, c_iIPADDR_FIELD_1_HIGH);
  499. // if editing an ip address fill the controls with the current information
  500. // if removing an ip address save it and fill the add dialog with it next time
  501. HWND hList = ::GetDlgItem(m_pParentDlg->m_hWnd, IDC_WINS_SERVER_LIST);
  502. RECT rect;
  503. ::GetWindowRect(hList, &rect);
  504. SetWindowPos(NULL, rect.left, rect.top, 0,0,
  505. SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
  506. m_hButton = GetDlgItem(IDOK);
  507. // add the address that was just removed
  508. if (m_pParentDlg->m_strNewIpAddress.size())
  509. {
  510. m_ipAddress.SetAddress(m_pParentDlg->m_strNewIpAddress.c_str());
  511. ::EnableWindow(m_hButton, TRUE);
  512. }
  513. else
  514. {
  515. m_pParentDlg->m_strNewIpAddress = L"";
  516. ::EnableWindow(m_hButton, FALSE);
  517. }
  518. ::SetFocus(m_ipAddress);
  519. return 0;
  520. }
  521. LRESULT CWinsServerDialog::OnContextMenu(UINT uMsg, WPARAM wParam,
  522. LPARAM lParam, BOOL& fHandled)
  523. {
  524. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  525. return 0;
  526. }
  527. LRESULT CWinsServerDialog::OnHelp(UINT uMsg, WPARAM wParam,
  528. LPARAM lParam, BOOL& fHandled)
  529. {
  530. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  531. Assert(lphi);
  532. if (HELPINFO_WINDOW == lphi->iContextType)
  533. {
  534. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  535. m_adwHelpIDs);
  536. }
  537. return 0;
  538. }
  539. LRESULT CWinsServerDialog::OnChange(WORD wNotifyCode, WORD wID,
  540. HWND hWndCtl, BOOL& fHandled)
  541. {
  542. if (m_ipAddress.IsBlank())
  543. ::EnableWindow(m_hButton, FALSE);
  544. else
  545. ::EnableWindow(m_hButton, TRUE);
  546. return 0;
  547. }
  548. LRESULT CWinsServerDialog::OnOk(WORD wNotifyCode, WORD wID,
  549. HWND hWndCtl, BOOL& fHandled)
  550. {
  551. tstring strIp;
  552. m_ipAddress.GetAddress(&strIp);
  553. // Validate
  554. if (!FIsIpInRange(strIp.c_str()))
  555. {
  556. // makes ip address lose focus so the control gets
  557. // IPN_FIELDCHANGED notification
  558. // also makes it consistent for when short-cut is used
  559. ::SetFocus(m_hButton);
  560. return 0;
  561. }
  562. int indexDup = Tcp_ListBox_FindStrExact(m_pParentDlg->m_hServers.m_hList, strIp.c_str());
  563. if (indexDup != LB_ERR && indexDup != m_iIndex)
  564. {
  565. NcMsgBox(m_hWnd,
  566. IDS_MSFT_TCP_TEXT,
  567. IDS_DUP_WINS_SERVER,
  568. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK,
  569. strIp.c_str());
  570. return 0;
  571. }
  572. if (m_pParentDlg->m_fEditState == FALSE)
  573. {
  574. // Get the current address from the control and
  575. // add them to the adapter if valid
  576. m_pParentDlg->m_strNewIpAddress = strIp;
  577. EndDialog(IDOK);
  578. }
  579. else // see if either changed
  580. {
  581. if (strIp != m_pParentDlg->m_strNewIpAddress)
  582. m_pParentDlg->m_strNewIpAddress = strIp; // update save addresses
  583. else
  584. EndDialog(IDCANCEL);
  585. }
  586. EndDialog(IDOK);
  587. return 0;
  588. }
  589. LRESULT CWinsServerDialog::OnCancel(WORD wNotifyCode, WORD wID,
  590. HWND hWndCtl, BOOL& fHandled)
  591. {
  592. EndDialog(IDCANCEL);
  593. return 0;
  594. }
  595. LRESULT CWinsServerDialog::OnIpFieldChange(int idCtrl, LPNMHDR pnmh,
  596. BOOL& fHandled)
  597. {
  598. LPNMIPADDRESS lpnmipa = (LPNMIPADDRESS) pnmh;
  599. int iLow = c_iIpLow;
  600. int iHigh = c_iIpHigh;
  601. if (0==lpnmipa->iField)
  602. {
  603. iLow = c_iIPADDR_FIELD_1_LOW;
  604. iHigh = c_iIPADDR_FIELD_1_HIGH;
  605. };
  606. IpCheckRange(lpnmipa, m_hWnd, iLow, iHigh);
  607. return 0;
  608. }
  609. //+---------------------------------------------------------------------------
  610. //
  611. // Purpose: Ensure the mouse cursor over the dialog is an Arrow.
  612. //
  613. LRESULT CWinsServerDialog::OnSetCursor (
  614. UINT uMsg,
  615. WPARAM wParam,
  616. LPARAM lParam,
  617. BOOL& bHandled)
  618. {
  619. if (LOWORD(lParam) == HTCLIENT)
  620. {
  621. SetCursor(LoadCursor(NULL, IDC_ARROW));
  622. }
  623. return 0;
  624. }