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.

647 lines
16 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // numcards.c
  8. //
  9. // Description:
  10. // This file contains the dialog procedure for the number of network
  11. // cards page (IDD_NUMBERNETCARDS).
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "pch.h"
  15. #include "resource.h"
  16. #define NET_SPIN_CONTROL_MIN 2
  17. #define NET_SPIN_CONTROL_MAX 20
  18. //----------------------------------------------------------------------------
  19. //
  20. // Function: DeleteList
  21. //
  22. // Purpose:
  23. //
  24. // Arguments:
  25. //
  26. // Returns:
  27. //
  28. //----------------------------------------------------------------------------
  29. VOID
  30. DeleteList( IN OUT NETWORK_ADAPTER_NODE *pNetworkAdapterList ) {
  31. NETWORK_ADAPTER_NODE *head;
  32. head = pNetworkAdapterList;
  33. while( head != NULL ) {
  34. pNetworkAdapterList = pNetworkAdapterList->next;
  35. free( head );
  36. head = pNetworkAdapterList;
  37. }
  38. pNetworkAdapterList = NULL;
  39. }
  40. //----------------------------------------------------------------------------
  41. //
  42. // Function: InstallDefaultNetComponents
  43. //
  44. // Purpose: Marks these three network components as installed and all other
  45. // network components as NOT installed
  46. // 1. Client for MS networks
  47. // 2. File and Print Sharing
  48. // 3. TCP/IP protocol
  49. //
  50. // Arguments: VOID
  51. //
  52. // Returns: VOID
  53. //
  54. //----------------------------------------------------------------------------
  55. VOID
  56. InstallDefaultNetComponents( VOID ) {
  57. NETWORK_COMPONENT *pNetComponent;
  58. for( pNetComponent = NetSettings.NetComponentsList;
  59. pNetComponent;
  60. pNetComponent = pNetComponent->next )
  61. {
  62. if( pNetComponent->iPosition == MS_CLIENT_POSITION ||
  63. pNetComponent->iPosition == FILE_AND_PRINT_SHARING_POSITION ||
  64. pNetComponent->iPosition == TCPIP_POSITION )
  65. {
  66. pNetComponent->bInstalled = TRUE;
  67. }
  68. else
  69. {
  70. pNetComponent->bInstalled = FALSE;
  71. }
  72. }
  73. }
  74. //----------------------------------------------------------------------------
  75. //
  76. // Function: ResetNetworkAdapter
  77. //
  78. // Purpose: Sets all network card (specified by the formal argument) settings
  79. // to their default values
  80. //
  81. // Arguments:
  82. //
  83. // Returns:
  84. //
  85. //----------------------------------------------------------------------------
  86. VOID
  87. ResetNetworkAdapter( OUT NETWORK_ADAPTER_NODE *pNetworkCard )
  88. {
  89. // ISSUE-2002/02/28-stelo- make sure every network card var is reset here
  90. if( pNetworkCard != NULL ) {
  91. pNetworkCard->next = NULL;
  92. pNetworkCard->previous = NULL;
  93. pNetworkCard->szPlugAndPlayID[0] = _T('\0');
  94. pNetworkCard->bObtainIPAddressAutomatically = TRUE;
  95. pNetworkCard->szDNSDomainName[0] = _T('\0');
  96. // initialize NetBIOS to "Use value generated by DHCP" option
  97. pNetworkCard->iNetBiosOption = 0;
  98. ResetNameList( &pNetworkCard->Tcpip_IpAddresses );
  99. ResetNameList( &pNetworkCard->Tcpip_SubnetMaskAddresses );
  100. ResetNameList( &pNetworkCard->Tcpip_GatewayAddresses );
  101. ResetNameList( &pNetworkCard->Tcpip_DnsAddresses );
  102. ResetNameList( &pNetworkCard->Tcpip_WinsAddresses );
  103. lstrcpyn( pNetworkCard->szFrameType, _T("0xFF"), AS(pNetworkCard->szFrameType) );
  104. lstrcpyn( pNetworkCard->szNetworkNumber, _T("00000000"), AS(pNetworkCard->szNetworkNumber) );
  105. }
  106. }
  107. //----------------------------------------------------------------------------
  108. //
  109. // Function: CreateListWithDefaults
  110. //
  111. // Purpose:
  112. //
  113. // Arguments:
  114. //
  115. // Returns:
  116. //
  117. //----------------------------------------------------------------------------
  118. VOID
  119. CreateListWithDefaults( OUT NETWORK_ADAPTER_NODE *pNetworkAdapter )
  120. {
  121. NETWORK_COMPONENT *pNetComponent;
  122. //
  123. // Initialize all the namelists to 0s
  124. //
  125. ZeroOut( pNetworkAdapter );
  126. ResetNetworkAdapter( pNetworkAdapter );
  127. //
  128. // Initialize the entire list to be NOT installed
  129. //
  130. for( pNetComponent = NetSettings.NetComponentsList;
  131. pNetComponent;
  132. pNetComponent = pNetComponent->next )
  133. {
  134. pNetComponent->bInstalled = FALSE;
  135. }
  136. }
  137. //----------------------------------------------------------------------------
  138. //
  139. // Function: ZeroOut
  140. //
  141. // Purpose: fill the namelists with zero's
  142. // this is necessary to do on namelists before they are used
  143. //
  144. // Arguments: OUT NETWORK_ADAPTER_NODE *pNetworkNode - the node that contains
  145. // the namelists to be Zeroed
  146. //
  147. // Returns: VOID
  148. //
  149. //----------------------------------------------------------------------------
  150. VOID
  151. ZeroOut( OUT NETWORK_ADAPTER_NODE *pNetworkNode) {
  152. ZeroMemory( &pNetworkNode->Tcpip_IpAddresses,
  153. sizeof( NAMELIST ) );
  154. ZeroMemory( &pNetworkNode->Tcpip_SubnetMaskAddresses,
  155. sizeof( NAMELIST ) );
  156. ZeroMemory( &pNetworkNode->Tcpip_GatewayAddresses,
  157. sizeof( NAMELIST ) );
  158. ZeroMemory( &pNetworkNode->Tcpip_DnsAddresses,
  159. sizeof( NAMELIST ) );
  160. ZeroMemory( &pNetworkNode->Tcpip_WinsAddresses,
  161. sizeof( NAMELIST ) );
  162. }
  163. //----------------------------------------------------------------------------
  164. //
  165. // Function: AddNewNetworkAdapterNode
  166. //
  167. // Purpose: Adds a new Network Adapter Node (initialized to its default values)
  168. // onto the list given as the input arg
  169. //
  170. // This function only adds to the end of a list. If you do not pass
  171. // it the end of the list, the result is undefined.
  172. //
  173. // Arguments: IN OUT NETWORK_ADAPTER_NODE *pCurrentAdapter - node to add the
  174. // new node to
  175. //
  176. // Returns: VOID
  177. //
  178. //----------------------------------------------------------------------------
  179. VOID
  180. AddNewNetworkAdapterNode( IN OUT NETWORK_ADAPTER_NODE *pCurrentAdapter ) {
  181. pCurrentAdapter->next = malloc( sizeof( NETWORK_ADAPTER_NODE ) );
  182. if (pCurrentAdapter->next == NULL)
  183. {
  184. TerminateTheWizard(IDS_ERROR_OUTOFMEMORY);
  185. }
  186. CreateListWithDefaults( pCurrentAdapter->next );
  187. InstallDefaultNetComponents();
  188. pCurrentAdapter->next->next = NULL;
  189. pCurrentAdapter->next->previous = pCurrentAdapter;
  190. }
  191. //----------------------------------------------------------------------------
  192. //
  193. // Function: AdjustNetworkCardMemory
  194. //
  195. // Purpose: examines the Global list NetSettings.NetworkCardList
  196. // if more network cards are necessary, it allocates more lists
  197. // if fewer network cards are necessary, it deallocates the
  198. // appropriate number of lists
  199. // if they are equal, then do nothing
  200. // Therefore, when the function returns, the length of
  201. // NetSettings.NetworkCardList is equal to the new number of
  202. // network cards
  203. //
  204. // Arguments: IN int NewNumberOfNetworkCards -
  205. // IN int OldNumberOfNetworkCards -
  206. //
  207. // Returns: VOID
  208. //
  209. //----------------------------------------------------------------------------
  210. VOID
  211. AdjustNetworkCardMemory( IN int NewNumberOfNetworkCards,
  212. IN int OldNumberOfNetworkCards ) {
  213. INT i;
  214. NetSettings.pCurrentAdapter = NetSettings.NetworkAdapterHead;
  215. if( NewNumberOfNetworkCards > OldNumberOfNetworkCards ) {
  216. //
  217. // NewNumberOfNetworkCards-1, the -1 because there is always
  218. // at least 1 network adapter list
  219. //
  220. for( i = 0; i < NewNumberOfNetworkCards-1; i++ ) {
  221. //
  222. // Allocate more lists, if necessary
  223. //
  224. if( NetSettings.pCurrentAdapter->next == NULL ) {
  225. AddNewNetworkAdapterNode( NetSettings.pCurrentAdapter );
  226. }
  227. //
  228. // Advance to the next node
  229. //
  230. NetSettings.pCurrentAdapter = NetSettings.pCurrentAdapter->next;
  231. }
  232. }
  233. else if( NewNumberOfNetworkCards < OldNumberOfNetworkCards ) {
  234. NETWORK_ADAPTER_NODE* pTempNode; // used to hold the current position
  235. NETWORK_ADAPTER_NODE* pTempNode2; // used delete the list
  236. //
  237. // Advance to the last network list we are keeping and delete all
  238. // the ones after that
  239. //
  240. for( i = 0;
  241. i < (NewNumberOfNetworkCards - 1);
  242. i++ ) {
  243. NetSettings.pCurrentAdapter = NetSettings.pCurrentAdapter->next;
  244. }
  245. //
  246. // save the pointer to the rest of the list
  247. //
  248. pTempNode = NetSettings.pCurrentAdapter->next;
  249. NetSettings.pCurrentAdapter->next = NULL;
  250. for( ;
  251. i < NewNumberOfNetworkCards;
  252. i++ ) {
  253. pTempNode2 = pTempNode;
  254. pTempNode = pTempNode->next;
  255. //
  256. // deallocate the rest of the list
  257. //
  258. DeleteList( pTempNode2 );
  259. }
  260. }
  261. //
  262. // Reset NetSettings.pCurrentNetworkList to the first node in the list
  263. //
  264. NetSettings.pCurrentAdapter = NetSettings.NetworkAdapterHead;
  265. }
  266. //----------------------------------------------------------------------------
  267. //
  268. // Function: EnableNetCardControls
  269. //
  270. // Purpose: Greys or ungreys the 3 controls that let the user change the
  271. // number of network cards installed
  272. //
  273. // Arguments:
  274. //
  275. // Returns: VOID
  276. //
  277. //----------------------------------------------------------------------------
  278. VOID
  279. EnableNetCardControls( IN HWND hwnd, IN BOOL bState ) {
  280. //
  281. // Grab handles to each of the controls
  282. //
  283. HWND hHowManyText = GetDlgItem( hwnd, IDC_HOWMANY_STATIC );
  284. HWND hCountEditBox = GetDlgItem( hwnd, IDC_NUM_CONNECT );
  285. HWND hSpinControl = GetDlgItem( hwnd, IDC_NUMBERNETADAPTERS_SPIN );
  286. //
  287. // Grey or ungrey them appropriately
  288. //
  289. EnableWindow( hHowManyText, bState );
  290. EnableWindow( hCountEditBox, bState );
  291. EnableWindow( hSpinControl, bState );
  292. //
  293. // Set the initial value of the spin control
  294. //
  295. if( bState && NetSettings.iNumberOfNetworkCards > 1 ) {
  296. TCHAR szNumberOfNetCards[3];
  297. _itow( NetSettings.iNumberOfNetworkCards, szNumberOfNetCards, 10 );
  298. SetWindowText( hCountEditBox, szNumberOfNetCards );
  299. }
  300. }
  301. //----------------------------------------------------------------------------
  302. //
  303. // Function: OnNumCardsInitDialog
  304. //
  305. // Purpose:
  306. //
  307. // Arguments: IN HWND hwnd - handle to the dialog
  308. //
  309. // Returns: VOID
  310. //
  311. //----------------------------------------------------------------------------
  312. VOID
  313. OnNumCardsInitDialog( IN HWND hwnd ) {
  314. //
  315. // Set the range on the spin control: NET_SPIN_CONTROL_MIN to
  316. // NET_SPIN_CONTROL_MAX
  317. //
  318. SendDlgItemMessage( hwnd,
  319. IDC_NUMBERNETADAPTERS_SPIN,
  320. UDM_SETRANGE32,
  321. NET_SPIN_CONTROL_MIN,
  322. NET_SPIN_CONTROL_MAX );
  323. //
  324. // Set the default value for the spin control
  325. //
  326. SendDlgItemMessage( hwnd,
  327. IDC_NUMBERNETADAPTERS_SPIN,
  328. UDM_SETPOS,
  329. 0,
  330. NET_SPIN_CONTROL_MIN );
  331. }
  332. //----------------------------------------------------------------------------
  333. //
  334. // Function: OnNumberNetCardsSetActive
  335. //
  336. // Purpose:
  337. //
  338. // Arguments: IN HWND hwnd - handle to the dialog
  339. //
  340. // Returns: VOID
  341. //
  342. //----------------------------------------------------------------------------
  343. VOID
  344. OnNumberNetCardsSetActive( IN HWND hwnd ) {
  345. if( NetSettings.iNumberOfNetworkCards < 2 ) {
  346. //
  347. // One network adapter radio button chosen
  348. //
  349. CheckRadioButton( hwnd,
  350. IDC_ONENETWORKADAPTER,
  351. IDC_MULTIPLENETWORKADPTERS,
  352. IDC_ONENETWORKADAPTER );
  353. //
  354. // The controls under the multiple adapters greyed-out
  355. //
  356. EnableNetCardControls( hwnd, FALSE );
  357. }
  358. else {
  359. //
  360. // We are in the multiple adapter case
  361. //
  362. //
  363. // Multiple network adapter radio button chosen
  364. //
  365. CheckRadioButton( hwnd,
  366. IDC_ONENETWORKADAPTER,
  367. IDC_MULTIPLENETWORKADPTERS,
  368. IDC_MULTIPLENETWORKADPTERS );
  369. //
  370. // The controls under the multiple adapters enabled
  371. //
  372. EnableNetCardControls( hwnd, TRUE );
  373. }
  374. PropSheet_SetWizButtons( GetParent(hwnd), PSWIZB_BACK | PSWIZB_NEXT );
  375. }
  376. //----------------------------------------------------------------------------
  377. //
  378. // Function: OnWizNextNumCards
  379. //
  380. // Purpose:
  381. //
  382. // Arguments: IN HWND hwnd - handle to the dialog
  383. //
  384. // Returns: VOID
  385. //
  386. //----------------------------------------------------------------------------
  387. VOID
  388. OnWizNextNumCards( IN HWND hwnd ) {
  389. if( IsDlgButtonChecked( hwnd, IDC_ONENETWORKADAPTER ) == BST_CHECKED ) {
  390. //
  391. // Single network adapter case
  392. //
  393. NetSettings.iNumberOfNetworkCards = 1;
  394. }
  395. else {
  396. //
  397. // Multiple network adapter case
  398. //
  399. TCHAR szNumber[3];
  400. INT NewNumberOfNetworkCards;
  401. //
  402. // Convert the string number to an int
  403. //
  404. GetWindowText( GetDlgItem( hwnd, IDC_NUM_CONNECT ), szNumber, 3 );
  405. NewNumberOfNetworkCards = _ttoi( szNumber );
  406. //
  407. // Ensure the number of network cards stays within its appropriate
  408. // range
  409. //
  410. if( NewNumberOfNetworkCards < NET_SPIN_CONTROL_MIN ) {
  411. NewNumberOfNetworkCards = NET_SPIN_CONTROL_MIN;
  412. }
  413. else if( NewNumberOfNetworkCards > NET_SPIN_CONTROL_MAX ) {
  414. NewNumberOfNetworkCards = NET_SPIN_CONTROL_MAX;
  415. }
  416. //
  417. // Adjust memory for the network lists accordingly
  418. //
  419. AdjustNetworkCardMemory( NewNumberOfNetworkCards,
  420. NetSettings.iNumberOfNetworkCards );
  421. NetSettings.iNumberOfNetworkCards = NewNumberOfNetworkCards;
  422. }
  423. }
  424. //----------------------------------------------------------------------------
  425. //
  426. // Function: DlgNumberNetCardsPage
  427. //
  428. // Purpose:
  429. //
  430. // Arguments: standard Win32 dialog proc arguments
  431. //
  432. // Returns: standard Win32 dialog proc return value
  433. //
  434. //----------------------------------------------------------------------------
  435. INT_PTR CALLBACK DlgNumberNetCardsPage( IN HWND hwnd,
  436. IN UINT uMsg,
  437. IN WPARAM wParam,
  438. IN LPARAM lParam) {
  439. BOOL bStatus = TRUE;
  440. switch( uMsg ) {
  441. case WM_INITDIALOG: {
  442. OnNumCardsInitDialog( hwnd );
  443. break;
  444. }
  445. case WM_COMMAND: {
  446. switch ( LOWORD(wParam) ) {
  447. case IDC_ONENETWORKADAPTER:
  448. if ( HIWORD(wParam) == BN_CLICKED ) {
  449. EnableNetCardControls( hwnd, FALSE );
  450. }
  451. break;
  452. case IDC_MULTIPLENETWORKADPTERS:
  453. if ( HIWORD(wParam) == BN_CLICKED ) {
  454. EnableNetCardControls( hwnd, TRUE );
  455. }
  456. break;
  457. }
  458. break;
  459. }
  460. case WM_NOTIFY: {
  461. LPNMHDR pnmh = (LPNMHDR)lParam;
  462. switch( pnmh->code ) {
  463. case PSN_QUERYCANCEL:
  464. CancelTheWizard(hwnd); break;
  465. case PSN_SETACTIVE:
  466. OnNumberNetCardsSetActive( hwnd );
  467. break;
  468. case PSN_WIZBACK:
  469. bStatus = FALSE; break;
  470. case PSN_WIZNEXT:
  471. OnWizNextNumCards( hwnd );
  472. break;
  473. default:
  474. break;
  475. }
  476. break;
  477. }
  478. default:
  479. bStatus = FALSE;
  480. break;
  481. }
  482. return bStatus;
  483. }