Leaked source code of windows server 2003
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.

1807 lines
45 KiB

  1. // Copyright (c) 1995, Microsoft Corporation, all rights reserved
  2. //
  3. // util.c
  4. // Remote Access Common Dialog APIs
  5. // Utility routines
  6. // Listed alphabetically
  7. //
  8. // Steve Cobb 06/20/95
  9. #include "rasdlgp.h" // Our private header
  10. #include <dlgs.h> // Common dialog resource constants
  11. #include <lmwksta.h> // NetWkstaGetInfo
  12. #include <lmapibuf.h> // NetApiBufferFree
  13. #include <dsrole.h> // machine is a member of a workgroup or domain, etc.
  14. #include <tchar.h>
  15. typedef struct _COUNT_FREE_COM_PORTS_DATA
  16. {
  17. DTLLIST* pListPortsInUse;
  18. DWORD dwCount;
  19. } COUNT_FREE_COM_PORTS_DATA;
  20. const WCHAR c_szCurrentBuildNumber[] = L"CurrentBuildNumber";
  21. const WCHAR c_szWinVersionPath[] =
  22. L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
  23. const WCHAR c_szNt40BuildNumber[] = L"1381";
  24. //-----------------------------------------------------------------------------
  25. // Help maps
  26. //-----------------------------------------------------------------------------
  27. static DWORD g_adwPnHelp[] =
  28. {
  29. CID_LE_ST_Item, HID_PN_EB_NewNumber,
  30. CID_LE_EB_Item, HID_PN_EB_NewNumber,
  31. CID_LE_PB_Add, HID_PN_PB_Add,
  32. CID_LE_PB_Replace, HID_PN_PB_Replace,
  33. CID_LE_ST_List, HID_PN_LB_List,
  34. CID_LE_LB_List, HID_PN_LB_List,
  35. CID_LE_PB_Up, HID_PN_PB_Up,
  36. CID_LE_PB_Down, HID_PN_PB_Down,
  37. CID_LE_PB_Delete, HID_PN_PB_Delete,
  38. CID_LE_CB_Promote, HID_PN_CB_Promote,
  39. 0, 0
  40. };
  41. //-----------------------------------------------------------------------------
  42. // Local helper prototypes (alphabetically)
  43. //-----------------------------------------------------------------------------
  44. BOOL
  45. CountFreeComPorts(
  46. IN PWCHAR pszPort,
  47. IN HANDLE hData);
  48. //-----------------------------------------------------------------------------
  49. // Utility routines (alphabetically)
  50. //-----------------------------------------------------------------------------
  51. BOOL
  52. AllLinksAreModems(
  53. IN PBENTRY* pEntry )
  54. // Returns true if all links associated with the entry are modem links
  55. // (MXS or Unimodem), false otherwise.
  56. //
  57. {
  58. DTLNODE* pNode;
  59. if (pEntry->pdtllistLinks)
  60. {
  61. for (pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  62. pNode;
  63. pNode = DtlGetNextNode( pNode ))
  64. {
  65. PBLINK* pLink = (PBLINK* )DtlGetData( pNode );
  66. if (pLink->pbport.pbdevicetype != PBDT_Modem)
  67. {
  68. return FALSE;
  69. }
  70. }
  71. }
  72. return TRUE;
  73. }
  74. BOOL
  75. AllowDccWizard(
  76. IN HANDLE hConnection)
  77. // Finds out if there are any dcc devices installed on the local
  78. // machine or if there are any available com ports. If neither
  79. // condition is satisfied, then we return FALSE, otherwise TRUE.
  80. {
  81. DWORD dwErr, dwUsedCount = 0;
  82. COUNT_FREE_COM_PORTS_DATA CountFreeComPortsData,
  83. *pCfcpd = &CountFreeComPortsData;
  84. DTLNODE* pNodeP, *pNodeL, *pNode;
  85. BOOL bRet = FALSE;
  86. // Initialize
  87. ZeroMemory(pCfcpd, sizeof(COUNT_FREE_COM_PORTS_DATA));
  88. do
  89. {
  90. // Load ras if it wasn't already loaded
  91. dwErr = LoadRas( g_hinstDll, NULL );
  92. if (dwErr != 0)
  93. {
  94. return FALSE;
  95. }
  96. // Load in all of the ports and count the number of
  97. // dcc devices
  98. dwErr = LoadPortsList2(
  99. hConnection,
  100. &(pCfcpd->pListPortsInUse),
  101. FALSE);
  102. if (dwErr != NO_ERROR)
  103. {
  104. bRet = FALSE;
  105. break;
  106. }
  107. // Count the dcc devices
  108. for (pNodeL = DtlGetFirstNode( pCfcpd->pListPortsInUse );
  109. pNodeL;
  110. pNodeL = DtlGetNextNode( pNodeL ))
  111. {
  112. PBLINK* pLink = (PBLINK* )DtlGetData( pNodeL );
  113. if (pLink->pbport.dwType == RASET_Direct)
  114. {
  115. bRet = TRUE;
  116. break;
  117. }
  118. }
  119. if (bRet == TRUE)
  120. {
  121. break;
  122. }
  123. // pmay: 249346
  124. //
  125. // Only merge the com ports if the user is an admin since
  126. // admin privilege is required to install a null modem.
  127. //
  128. if (FIsUserAdminOrPowerUser())
  129. {
  130. // Count the number of available com ports
  131. dwErr = MdmEnumComPorts (
  132. CountFreeComPorts,
  133. (HANDLE)pCfcpd);
  134. if (dwErr != NO_ERROR)
  135. {
  136. bRet = FALSE;
  137. break;
  138. }
  139. bRet = (pCfcpd->dwCount > 0) ? TRUE : FALSE;
  140. }
  141. } while (FALSE);
  142. // Cleanup
  143. {
  144. if ( pCfcpd->pListPortsInUse )
  145. {
  146. DtlDestroyList(pCfcpd->pListPortsInUse, DestroyPortNode);
  147. }
  148. }
  149. return bRet;
  150. }
  151. DWORD
  152. AuthRestrictionsFromTypicalAuth(
  153. IN DWORD dwTypicalAuth )
  154. // Return the AR_F_* flag corresponding to the TA_* value 'dwTypicalAuth',
  155. // i.e. convert a typical authentication selection to a bitmask of
  156. // authentication protocols.
  157. //
  158. {
  159. if (dwTypicalAuth == TA_Secure)
  160. {
  161. return AR_F_TypicalSecure;
  162. }
  163. else if (dwTypicalAuth == TA_CardOrCert)
  164. {
  165. return AR_F_TypicalCardOrCert;
  166. }
  167. else
  168. {
  169. return AR_F_TypicalUnsecure;
  170. }
  171. }
  172. LONG GetGlobalCallbackActive( )
  173. {
  174. LONG ret = 0;
  175. __try
  176. {
  177. EnterCriticalSection( &g_csCallBacks );
  178. ret = g_ulCallbacksActive;
  179. TRACE1("GlobalActive Calls are:%ld",g_ulCallbacksActive);
  180. }
  181. __finally
  182. {
  183. LeaveCriticalSection( &g_csCallBacks );
  184. }
  185. return ret;
  186. }
  187. LONG IncGlobalCallbackActive( )
  188. {
  189. LONG ret = 0;
  190. __try
  191. {
  192. EnterCriticalSection( &g_csCallBacks );
  193. g_ulCallbacksActive++;
  194. ret = g_ulCallbacksActive;
  195. TRACE1("GlobalActive Calls are:%ld",g_ulCallbacksActive);
  196. }
  197. __finally
  198. {
  199. LeaveCriticalSection( &g_csCallBacks );
  200. }
  201. return ret;
  202. }
  203. LONG DecGlobalCallbackActive( )
  204. {
  205. LONG ret = 0;
  206. __try
  207. {
  208. EnterCriticalSection( &g_csCallBacks );
  209. if( 0 < g_ulCallbacksActive )
  210. {
  211. g_ulCallbacksActive -- ;
  212. }
  213. ret = g_ulCallbacksActive;
  214. TRACE1("GlobalActive Calls are:%ld", g_ulCallbacksActive);
  215. }
  216. __finally
  217. {
  218. LeaveCriticalSection( &g_csCallBacks );
  219. }
  220. return ret;
  221. }
  222. ULONG
  223. CallbacksActive(
  224. INT nSetTerminateAsap,
  225. BOOL* pfTerminateAsap )
  226. // If 'fSetTerminateAsap' >= 0, sets 'g_fTerminateAsap' flag to 'nSetTerminateAsap'.
  227. // If non-NULL, caller's '*pfTerminateAsap' is filled with the current value of
  228. // 'g_fTerminateAsap'.
  229. //
  230. // Returns the number of Rasdial callback threads active.
  231. //
  232. {
  233. ULONG ul;
  234. TRACE1( "CallbacksActive(%d)", nSetTerminateAsap );
  235. ul = 0;
  236. //For XPSP2 511810 and .Net 668164
  237. //
  238. __try
  239. {
  240. EnterCriticalSection( &g_csCallBacks );
  241. if (pfTerminateAsap)
  242. {
  243. *pfTerminateAsap = g_fTerminateAsap;
  244. }
  245. if (nSetTerminateAsap >= 0)
  246. {
  247. g_fTerminateAsap = (BOOL )nSetTerminateAsap;
  248. }
  249. ul = g_ulCallbacksActive;
  250. }
  251. __finally
  252. {
  253. LeaveCriticalSection( &g_csCallBacks );
  254. }
  255. TRACE1( "CallbacksActive=%d", ul );
  256. return ul;
  257. }
  258. VOID
  259. ContextHelp(
  260. IN const DWORD* padwMap,
  261. IN HWND hwndDlg,
  262. IN UINT unMsg,
  263. IN WPARAM wparam,
  264. IN LPARAM lparam)
  265. {
  266. ContextHelpX( padwMap, hwndDlg, unMsg, wparam, lparam, FALSE );
  267. }
  268. VOID
  269. ContextHelpX(
  270. IN const DWORD* padwMap,
  271. IN HWND hwndDlg,
  272. IN UINT unMsg,
  273. IN WPARAM wparam,
  274. IN LPARAM lparam,
  275. IN BOOL fRouter)
  276. // Calls WinHelp to popup context sensitive help. 'PadwMap' is an array
  277. // of control-ID help-ID pairs terminated with a 0,0 pair. 'UnMsg' is
  278. // WM_HELP or WM_CONTEXTMENU indicating the message received requesting
  279. // help. 'Wparam' and 'lparam' are the parameters of the message received
  280. // requesting help.
  281. //
  282. {
  283. HWND hwnd;
  284. UINT unType;
  285. TCHAR* pszHelpFile;
  286. ASSERT( unMsg==WM_HELP || unMsg==WM_CONTEXTMENU );
  287. // Don't try to do help if it won't work. See common\uiutil\ui.c.
  288. //
  289. {
  290. extern BOOL g_fNoWinHelp;
  291. if (g_fNoWinHelp)
  292. {
  293. return;
  294. }
  295. }
  296. if (unMsg == WM_HELP)
  297. {
  298. LPHELPINFO p = (LPHELPINFO )lparam;
  299. TRACE3( "ContextHelp(WM_HELP,t=%d,id=%d,h=$%08x)",
  300. p->iContextType, p->iCtrlId,p->hItemHandle );
  301. if (p->iContextType != HELPINFO_WINDOW)
  302. {
  303. return;
  304. }
  305. hwnd = p->hItemHandle;
  306. ASSERT( hwnd );
  307. unType = HELP_WM_HELP;
  308. }
  309. else
  310. {
  311. // Standard Win95 method that produces a one-item "What's This?" menu
  312. // that user must click to get help.
  313. //
  314. TRACE1( "ContextHelp(WM_CONTEXTMENU,h=$%08x)", wparam );
  315. hwnd = (HWND )wparam;
  316. unType = HELP_CONTEXTMENU;
  317. };
  318. if (fRouter)
  319. {
  320. pszHelpFile = g_pszRouterHelpFile;
  321. }
  322. else
  323. {
  324. pszHelpFile = g_pszHelpFile;
  325. }
  326. TRACE1( "WinHelp(%s)", pszHelpFile );
  327. WinHelp( hwnd, pszHelpFile, unType, (ULONG_PTR ) padwMap );
  328. }
  329. VOID
  330. CopyLinkPhoneNumberInfo(
  331. OUT DTLNODE* pDstLinkNode,
  332. IN DTLNODE* pSrcLinkNode )
  333. // Copies the source link's phone number information to the destination
  334. // link. Any existing destination information is properly destroyed. The
  335. // arguments are DTLNODEs containing PBLINKs.
  336. //
  337. {
  338. PBLINK* pSrcLink;
  339. PBLINK* pDstLink;
  340. DTLLIST* pDstList;
  341. pSrcLink = (PBLINK* )DtlGetData( pSrcLinkNode );
  342. pDstLink = (PBLINK* )DtlGetData( pDstLinkNode );
  343. pDstList =
  344. DtlDuplicateList(
  345. pSrcLink->pdtllistPhones, DuplicatePhoneNode, DestroyPhoneNode );
  346. if (pDstList)
  347. {
  348. DtlDestroyList( pDstLink->pdtllistPhones, DestroyPhoneNode );
  349. pDstLink->pdtllistPhones = pDstList;
  350. pDstLink->fPromoteAlternates = pSrcLink->fPromoteAlternates;
  351. pDstLink->fTryNextAlternateOnFail = pSrcLink->fTryNextAlternateOnFail;
  352. }
  353. }
  354. VOID
  355. CopyPszListToPhoneList(
  356. IN OUT PBLINK* pLink,
  357. IN DTLLIST* pListPhoneNumbers )
  358. // Converts the phone number list of 'pLink' to be list created using the
  359. // the list of Psz phone numbers 'pListPhoneNumbers' for phone numbers.
  360. //
  361. {
  362. DTLNODE* pNodeP;
  363. DTLNODE* pNodeZ;
  364. // Empty the existing list of PBPHONE nodes.
  365. //
  366. while (pNodeP = DtlGetFirstNode( pLink->pdtllistPhones ))
  367. {
  368. DtlRemoveNode( pLink->pdtllistPhones, pNodeP );
  369. DestroyPhoneNode( pNodeP );
  370. }
  371. // Recreate the list of PBPHONE nodes from the list of PSZ nodes.
  372. //
  373. for (pNodeZ = DtlGetFirstNode( pListPhoneNumbers );
  374. pNodeZ;
  375. pNodeZ = DtlGetNextNode( pNodeZ ))
  376. {
  377. PBPHONE* pPhone;
  378. pNodeP = CreatePhoneNode();
  379. if (!pNodeP)
  380. {
  381. continue;
  382. }
  383. pPhone = (PBPHONE* )DtlGetData( pNodeP );
  384. ASSERT( pPhone );
  385. Free0( pPhone->pszPhoneNumber );
  386. pPhone->pszPhoneNumber =
  387. StrDup( (TCHAR* )DtlGetData( pNodeZ ) );
  388. DtlAddNodeLast( pLink->pdtllistPhones, pNodeP );
  389. }
  390. }
  391. BOOL
  392. CountFreeComPorts(
  393. IN PWCHAR pszPort,
  394. IN HANDLE hData)
  395. // Com port enumeration function that counts the list of
  396. // free com ports. Returns TRUE to stop enumeration (see
  397. // MdmEnumComPorts)
  398. {
  399. COUNT_FREE_COM_PORTS_DATA* pfcpData = (COUNT_FREE_COM_PORTS_DATA*)hData;
  400. DTLLIST* pListUsed = pfcpData->pListPortsInUse;
  401. DTLNODE* pNodeP, *pNodeL, *pNode;
  402. // If the given port is in the used list, then return
  403. // so that it is not added to the list of free ports and
  404. // so that enumeration continues.
  405. for (pNodeL = DtlGetFirstNode( pListUsed );
  406. pNodeL;
  407. pNodeL = DtlGetNextNode( pNodeL ))
  408. {
  409. PBLINK* pLink = (PBLINK* )DtlGetData( pNodeL );
  410. ASSERT( pLink->pbport.pszPort );
  411. // The port already appears in a link in the list.
  412. if (lstrcmp( pLink->pbport.pszPort, pszPort ) == 0)
  413. return FALSE;
  414. }
  415. // The port is not in use. Increment the count.
  416. pfcpData->dwCount += 1;
  417. return FALSE;
  418. }
  419. HWND
  420. CreateWizardBitmap(
  421. IN HWND hwndDlg,
  422. IN BOOL fPage )
  423. // Create a static control that displays the RAS wizard bitmap at the
  424. // standard place on dialog 'hwndDlg'. 'FPage' is set if the bitmap is
  425. // being placed on a property page, false for the equivalent placement on
  426. // a dialog.
  427. //
  428. // Returns the bitmap window handle or NULL or error.
  429. //
  430. {
  431. HWND hwnd;
  432. INT x;
  433. INT y;
  434. if (fPage)
  435. {
  436. x = y = 0;
  437. }
  438. else
  439. {
  440. x = y = 10;
  441. }
  442. hwnd =
  443. CreateWindowEx(
  444. 0,
  445. TEXT("static"),
  446. NULL,
  447. WS_VISIBLE | WS_CHILD | SS_SUNKEN | SS_BITMAP,
  448. x, y, 80, 140,
  449. hwndDlg,
  450. (HMENU )CID_BM_Wizard,
  451. g_hinstDll,
  452. NULL );
  453. if (hwnd)
  454. {
  455. if (!g_hbmWizard)
  456. {
  457. g_hbmWizard = LoadBitmap(
  458. g_hinstDll, MAKEINTRESOURCE( BID_Wizard ) );
  459. }
  460. SendMessage( hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM )g_hbmWizard );
  461. }
  462. return hwnd;
  463. }
  464. TCHAR*
  465. DisplayPszFromDeviceAndPort(
  466. IN TCHAR* pszDevice,
  467. IN TCHAR* pszPort )
  468. // Returns address of heap block psz containing the MXS modem list display
  469. // form, i.e. the device name 'pszDevice' followed by the port name
  470. // 'pszPort'. It's caller's responsibility to Free the returned string.
  471. //
  472. {
  473. TCHAR* pszResult;
  474. TCHAR* pszD;
  475. if (pszDevice)
  476. {
  477. pszD = NULL;
  478. }
  479. else
  480. {
  481. pszD = pszDevice = PszFromId( g_hinstDll, SID_UnknownDevice );
  482. }
  483. pszResult = PszFromDeviceAndPort( pszDevice, pszPort );
  484. Free0( pszD );
  485. return pszResult;
  486. }
  487. TCHAR*
  488. DisplayPszFromPpbport(
  489. IN PBPORT* pPort,
  490. OUT DWORD* pdwDeviceIcon )
  491. // Returns address of heap block psz containing the device display form of
  492. // the 'pPort', e.g. "Modem - KTel 28.8 Fax Plus" It's caller's
  493. // responsibility to Free the returned string. If non-NULL,
  494. // '*pdwDeviceIcon' is set to the DI_* device icon code corresponding to
  495. // the device. DI_* codes are used with the RAS ListView extensions to
  496. // show the correct item icon.
  497. //
  498. {
  499. TCHAR* pszFormat;
  500. TCHAR* pszD;
  501. TCHAR* pszDT;
  502. TCHAR* pszDevice;
  503. TCHAR* pszDeviceType;
  504. TCHAR* pszResult;
  505. DWORD dwDeviceIcon;
  506. LPCTSTR pszChannel = NULL;
  507. // These are set if a resource string is read that must be Freed later.
  508. //
  509. pszDT = NULL;
  510. pszD = NULL;
  511. if (pPort->pszDevice)
  512. {
  513. pszDevice = pPort->pszDevice;
  514. }
  515. else
  516. {
  517. pszDevice = PszFromId( g_hinstDll, SID_UnknownDevice );
  518. if(NULL == pszDevice)
  519. {
  520. return NULL;
  521. }
  522. pszD = pszDevice;
  523. }
  524. // Set default format and device icon, though they may be changed below.
  525. //
  526. pszFormat = TEXT("%s - %s (%s)");
  527. dwDeviceIcon = DI_Adapter;
  528. if (pPort->pbdevicetype == PBDT_Modem
  529. && !(pPort->dwFlags & PBP_F_NullModem))
  530. {
  531. pszDeviceType = PszFromId( g_hinstDll, SID_Modem );
  532. pszDT = pszDeviceType;
  533. dwDeviceIcon = DI_Modem;
  534. }
  535. else if (pPort->pbdevicetype == PBDT_Isdn)
  536. {
  537. pszDeviceType = PszFromId( g_hinstDll, SID_Isdn );
  538. pszDT = pszDeviceType;
  539. pszFormat = TEXT("%s %s - %s");
  540. }
  541. else if (pPort->pbdevicetype == PBDT_X25)
  542. {
  543. pszDeviceType = PszFromId( g_hinstDll, SID_X25 );
  544. pszDT = pszDeviceType;
  545. }
  546. else if (pPort->pbdevicetype == PBDT_Pad)
  547. {
  548. pszDeviceType = PszFromId( g_hinstDll, SID_X25Pad );
  549. pszDT = pszDeviceType;
  550. }
  551. else
  552. {
  553. // Don't know the device type, so just bag the device descriptive word
  554. // and let the device name stand alone.
  555. //
  556. pszDeviceType = TEXT("");
  557. pszFormat = TEXT("%s%s (%s)");
  558. }
  559. if(NULL == pszDeviceType)
  560. {
  561. pszDeviceType = TEXT("");
  562. }
  563. if(pPort->pbdevicetype != PBDT_Isdn)
  564. {
  565. pszResult = Malloc(
  566. (lstrlen( pszFormat ) + lstrlen( pszDeviceType ) + lstrlen( pszDevice ) + lstrlen( pPort->pszPort ))
  567. * sizeof(TCHAR) );
  568. }
  569. else
  570. {
  571. pszChannel = PszLoadString( g_hinstDll, SID_Channel );
  572. if(NULL == pszChannel)
  573. {
  574. pszChannel = TEXT("");
  575. }
  576. // For isdn use the following format
  577. // "Isdn channel - <DeviceName>
  578. // Talk to steve falcon about this if you have issues
  579. // with special casing isdn.
  580. //
  581. pszResult = Malloc(
  582. (lstrlen( pszFormat ) + lstrlen( pszDeviceType ) + lstrlen(pszChannel) + lstrlen( pszDevice ))
  583. * sizeof(TCHAR));
  584. }
  585. if (pszResult)
  586. {
  587. if(pPort->pbdevicetype != PBDT_Isdn)
  588. {
  589. wsprintf( pszResult, pszFormat, pszDeviceType, pszDevice, pPort->pszPort);
  590. }
  591. else
  592. {
  593. ASSERT(NULL != pszChannel);
  594. wsprintf( pszResult, pszFormat, pszDeviceType, pszChannel, pszDevice);
  595. }
  596. }
  597. if (pdwDeviceIcon)
  598. {
  599. #if 1
  600. // Per SteveFal. Wants "modem" icon for all if Device-Manager-style
  601. // physically descriptive icons cannot be used.
  602. //
  603. dwDeviceIcon = DI_Modem;
  604. #endif
  605. *pdwDeviceIcon = dwDeviceIcon;
  606. }
  607. Free0( pszD );
  608. Free0( pszDT );
  609. return pszResult;
  610. }
  611. VOID
  612. EnableCbWithRestore(
  613. IN HWND hwndCb,
  614. IN BOOL fEnable,
  615. IN BOOL fDisabledCheck,
  616. IN OUT BOOL* pfRestore )
  617. // Enable/disable the checkbox 'hwndCb' based on the 'fEnable' flag
  618. // including stashing and restoring a cached value '*pfRestore' when
  619. // disabled. When disabling, the check value is set to 'fDisabledCheck'.
  620. //
  621. {
  622. if (fEnable)
  623. {
  624. if (!IsWindowEnabled( hwndCb ))
  625. {
  626. // Toggling to enabled. Restore the stashed check value.
  627. //
  628. Button_SetCheck( hwndCb, *pfRestore );
  629. EnableWindow( hwndCb, TRUE );
  630. }
  631. }
  632. else
  633. {
  634. if (IsWindowEnabled( hwndCb ))
  635. {
  636. // Toggling to disabled. Stashed the current check value.
  637. //
  638. *pfRestore = Button_GetCheck( hwndCb );
  639. Button_SetCheck( hwndCb, fDisabledCheck );
  640. EnableWindow( hwndCb, FALSE );
  641. }
  642. }
  643. }
  644. VOID
  645. EnableLbWithRestore(
  646. IN HWND hwndLb,
  647. IN BOOL fEnable,
  648. IN OUT INT* piRestore )
  649. // Enable/disable the combobox 'hwndLb' based on the 'fEnable' flag. If
  650. // disabling, '*piRestore' is loaded with the stashed selection index and
  651. // a blank item is added to the front of the list and selected. This is
  652. // undone if enabling.
  653. //
  654. {
  655. if (fEnable)
  656. {
  657. if (!IsWindowEnabled( hwndLb ))
  658. {
  659. // Toggling to enabled. Restore the stashed selection.
  660. //
  661. ComboBox_DeleteString( hwndLb, 0 );
  662. ComboBox_SetCurSelNotify( hwndLb, *piRestore );
  663. EnableWindow( hwndLb, TRUE );
  664. }
  665. }
  666. else
  667. {
  668. if (IsWindowEnabled( hwndLb ))
  669. {
  670. // Toggling to disabled. Stash the selection index.
  671. //
  672. *piRestore = ComboBox_GetCurSel( hwndLb );
  673. ComboBox_InsertString( hwndLb, 0, TEXT("") );
  674. ComboBox_SetItemData( hwndLb, 0, NULL );
  675. ComboBox_SetCurSelNotify( hwndLb, 0 );
  676. EnableWindow( hwndLb, FALSE );
  677. }
  678. }
  679. }
  680. DTLNODE*
  681. FirstPhoneNodeFromPhoneList(
  682. IN DTLLIST* pListPhones )
  683. // Return the first PBPHONE node in list of PBPHONEs 'pListPhones' or a
  684. // default node if none. Returns NULL if out of memory.
  685. //
  686. {
  687. DTLNODE* pFirstNode;
  688. DTLNODE* pNode;
  689. pFirstNode = DtlGetFirstNode( pListPhones );
  690. if (pFirstNode)
  691. {
  692. pNode = DuplicatePhoneNode( pFirstNode );
  693. }
  694. else
  695. {
  696. pNode = CreatePhoneNode();
  697. }
  698. return pNode;
  699. }
  700. VOID
  701. FirstPhoneNodeToPhoneList(
  702. IN DTLLIST* pListPhones,
  703. IN DTLNODE* pNewNode )
  704. // Replace the first PBPHONE node in list of PBPHONEs 'pListPhones' with
  705. // 'pNewNode', deleting any existing first node. Caller's actual
  706. // 'pNewNode', not a copy, is linked.
  707. //
  708. {
  709. DTLNODE* pFirstNode;
  710. DTLNODE* pNode;
  711. pFirstNode = DtlGetFirstNode( pListPhones );
  712. if (pFirstNode)
  713. {
  714. DtlRemoveNode( pListPhones, pFirstNode );
  715. DestroyPhoneNode( pFirstNode );
  716. }
  717. DtlAddNodeFirst( pListPhones, pNewNode );
  718. }
  719. #if 0 //!!!
  720. TCHAR*
  721. FirstPhoneNumberFromEntry(
  722. IN PBENTRY* pEntry )
  723. // Returns the first phone number of the first link of entry 'pEntry' or
  724. // an empty string if none. The returned address is into the list of
  725. // phone numbers and should be copied if it needs to be stored.
  726. //
  727. {
  728. TCHAR* pszPhoneNumber;
  729. DTLNODE* pNode;
  730. PBLINK* pLink;
  731. TRACE( "FirstPhoneNumberFromEntry" );
  732. ASSERT( pEntry->pdtllistLinks );
  733. pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  734. ASSERT( pNode );
  735. pLink = (PBLINK* )DtlGetData( pNode );
  736. ASSERT( pLink );
  737. return FirstPszFromList( pLink->pdtllistPhoneNumbers );
  738. }
  739. #endif
  740. TCHAR*
  741. FirstPszFromList(
  742. IN DTLLIST* pPszList )
  743. // Returns the first string from the first node of 'pPszList' or an empty
  744. // string if none. The returned address is into the list and should be
  745. // copied if it needs to be stored.
  746. //
  747. {
  748. TCHAR* psz;
  749. DTLNODE* pNode;
  750. TRACE( "FirstPszFromList" );
  751. if (DtlGetNodes( pPszList ) > 0)
  752. {
  753. pNode = DtlGetFirstNode( pPszList );
  754. ASSERT( pNode );
  755. psz = (TCHAR* )DtlGetData( pNode );
  756. ASSERT( psz );
  757. }
  758. else
  759. {
  760. psz = TEXT("");
  761. }
  762. return psz;
  763. }
  764. #if 0 //!!!
  765. DWORD
  766. FirstPhoneNumberToEntry(
  767. IN PBENTRY* pEntry,
  768. IN TCHAR* pszPhoneNumber )
  769. // Sets the first phone number of the first link of entry 'pEntry' to
  770. // 'pszPhoneNumber'.
  771. //
  772. // Returns 0 if successful, or an error code.
  773. //
  774. {
  775. DTLNODE* pNode;
  776. PBLINK* pLink;
  777. TCHAR* pszNew;
  778. TRACE( "FirstPhoneNumberToEntry" );
  779. ASSERT( pEntry->pdtllistLinks );
  780. pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  781. ASSERT( pNode );
  782. pLink = (PBLINK* )DtlGetData( pNode );
  783. ASSERT( pLink );
  784. ASSERT( pLink->pdtllistPhoneNumbers );
  785. return FirstPszToList( pLink->pdtllistPhoneNumbers, pszPhoneNumber );
  786. }
  787. #endif
  788. DWORD
  789. FirstPszToList(
  790. IN DTLLIST* pPszList,
  791. IN TCHAR* psz )
  792. // Sets the string of the first node of the list 'pPszList' to a copy of
  793. // 'psz'. If 'psz' is "" the first node is deleted.
  794. //
  795. // Returns 0 if successful, or an error code.
  796. //
  797. {
  798. DTLNODE* pNode;
  799. TCHAR* pszNew;
  800. ASSERT( pPszList );
  801. // Delete the existing first node, if any.
  802. //
  803. if (DtlGetNodes( pPszList ) > 0)
  804. {
  805. pNode = DtlGetFirstNode( pPszList );
  806. DtlRemoveNode( pPszList, pNode );
  807. DestroyPszNode( pNode );
  808. }
  809. // Create a new first node and link it. An empty string is not added.
  810. //
  811. if (*psz == TEXT('\0'))
  812. return 0;
  813. pszNew = StrDup( psz );
  814. pNode = DtlCreateNode( pszNew, 0 );
  815. if (!pszNew || !pNode)
  816. {
  817. Free0( pszNew );
  818. return ERROR_NOT_ENOUGH_MEMORY;
  819. }
  820. DtlAddNodeFirst( pPszList, pNode );
  821. return 0;
  822. }
  823. //
  824. // Function: GetBoldWindowFont
  825. //
  826. // Purpose: Generate bold or large bold fonts based on the font of the
  827. // window specified
  828. //
  829. // Parameters: hwnd [IN] - Handle of window to base font on
  830. // fLargeFont [IN] - If TRUE, generate a 12 point bold font for
  831. // use in the wizard "welcome" page.
  832. // pBoldFont [OUT] - The newly generated font, NULL if the
  833. //
  834. // Returns: nothing
  835. //
  836. VOID
  837. GetBoldWindowFont(
  838. IN HWND hwnd,
  839. IN BOOL fLargeFont,
  840. OUT HFONT * pBoldFont)
  841. {
  842. LOGFONT BoldLogFont;
  843. HFONT hFont;
  844. TCHAR FontSizeString[MAX_PATH];
  845. INT FontSize;
  846. HDC hdc;
  847. *pBoldFont = NULL;
  848. // Get the font used by the specified window
  849. //
  850. hFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0L);
  851. if (NULL == hFont)
  852. {
  853. // If not found then the control is using the system font
  854. //
  855. hFont = (HFONT)GetStockObject(SYSTEM_FONT);
  856. }
  857. if (hFont)
  858. {
  859. // Get the font info so we can generate the BOLD version
  860. //
  861. if (GetObject(hFont, sizeof(BoldLogFont), &BoldLogFont))
  862. {
  863. // Create the Bold Font
  864. //
  865. BoldLogFont.lfWeight = FW_BOLD;
  866. hdc = GetDC(hwnd);
  867. if (hdc)
  868. {
  869. // Large (tall) font is an option
  870. //
  871. if (fLargeFont)
  872. {
  873. // Load size and name from resources,
  874. // since these may change
  875. // from locale to locale based on the
  876. // size of the system font, etc.
  877. //
  878. UINT nLen;
  879. PWCHAR pszFontName = NULL, pszFontSize = NULL;
  880. pszFontName = (PWCHAR)PszLoadString(
  881. g_hinstDll,
  882. SID_LargeFontName);
  883. pszFontSize = (PWCHAR)PszLoadString(
  884. g_hinstDll,
  885. SID_LargeFontSize);
  886. if (pszFontName != NULL)
  887. {
  888. lstrcpyn(
  889. BoldLogFont.lfFaceName,
  890. pszFontName,
  891. sizeof(BoldLogFont.lfFaceName) / sizeof(TCHAR));
  892. }
  893. FontSize = 12;
  894. nLen = lstrlen(pszFontName);
  895. if (pszFontSize)
  896. {
  897. lstrcpyn(
  898. FontSizeString,
  899. pszFontSize,
  900. sizeof(FontSizeString) / sizeof(TCHAR));
  901. FontSize = wcstoul((const TCHAR*)FontSizeString, NULL, 10);
  902. }
  903. BoldLogFont.lfHeight =
  904. 0 - (GetDeviceCaps(hdc,LOGPIXELSY) * FontSize / 72);
  905. //Free0(pszFontName);
  906. //Free0(pszFontSize);
  907. }
  908. *pBoldFont = CreateFontIndirect(&BoldLogFont);
  909. ReleaseDC(hwnd, hdc);
  910. }
  911. }
  912. }
  913. }
  914. DWORD
  915. GetDefaultEntryName(
  916. IN PBFILE* pFile,
  917. IN DWORD dwType,
  918. IN BOOL fRouter,
  919. OUT TCHAR** ppszName )
  920. // Loads a default entry name into '*ppszName' that is unique within open
  921. // phonebook 'pFile', or if NULL, in all default phonebooks. 'FRouter' is
  922. // set if a router-style name should be chosen rather than a client-style
  923. // name. It is caller's responsibility to Free the returned string.
  924. //
  925. // Returns 0 if successful or an error code.
  926. //
  927. {
  928. DWORD dwErr;
  929. TCHAR szBuf[ RAS_MaxEntryName + 1 ];
  930. UINT unSid;
  931. LPCTSTR pszDefault;
  932. DWORD dwDefaultLen;
  933. LONG lNum;
  934. PBFILE file;
  935. DTLNODE* pNode;
  936. *ppszName = NULL;
  937. if (fRouter)
  938. {
  939. unSid = SID_DefaultRouterEntryName;
  940. }
  941. else
  942. {
  943. unSid = SID_DefaultEntryName;
  944. if (RASET_Vpn == dwType)
  945. {
  946. unSid = SID_DefaultVpnEntryName;
  947. }
  948. else if (RASET_Direct == dwType)
  949. {
  950. unSid = SID_DefaultDccEntryName;
  951. }
  952. else if (RASET_Broadband == dwType)
  953. {
  954. unSid = SID_DefaultBbEntryName;
  955. }
  956. }
  957. pszDefault = PszLoadString( g_hinstDll, unSid );
  958. lstrcpyn( szBuf, pszDefault, sizeof(szBuf) / sizeof(TCHAR) );
  959. dwDefaultLen = lstrlen( pszDefault ) + 1; // +1 for extra space below
  960. lNum = 2;
  961. for (;;)
  962. {
  963. if (pFile)
  964. {
  965. if (!EntryNodeFromName( pFile->pdtllistEntries, szBuf ))
  966. {
  967. break;
  968. }
  969. }
  970. else
  971. {
  972. if (GetPbkAndEntryName(
  973. NULL, szBuf, RPBF_NoCreate, &file, &pNode ) == 0)
  974. {
  975. ClosePhonebookFile( &file );
  976. }
  977. else
  978. {
  979. break;
  980. }
  981. }
  982. // Duplicate entry found so increment the default name and try the
  983. // next one.
  984. //
  985. lstrcpyn( szBuf, pszDefault, sizeof(szBuf) / sizeof(TCHAR) );
  986. lstrcat( szBuf, TEXT(" "));
  987. LToT( lNum, szBuf + dwDefaultLen, 10 );
  988. ++lNum;
  989. }
  990. *ppszName = StrDup( szBuf );
  991. if (!*ppszName)
  992. {
  993. return ERROR_NOT_ENOUGH_MEMORY;
  994. }
  995. return ERROR_SUCCESS;
  996. }
  997. BOOL
  998. IsLocalPad(
  999. IN PBENTRY* pEntry )
  1000. // Returns true if 'pEntry' is a local PAD device, i.e. the first link of
  1001. // the entry has device type "pad", false otherwise.
  1002. //
  1003. {
  1004. PBLINK* pLink;
  1005. DTLNODE* pNode;
  1006. if (!pEntry)
  1007. {
  1008. return FALSE;
  1009. }
  1010. ASSERT( pEntry->pdtllistLinks );
  1011. pNode = DtlGetFirstNode( pEntry->pdtllistLinks );
  1012. ASSERT( pNode );
  1013. pLink = (PBLINK* )DtlGetData( pNode );
  1014. ASSERT( pLink );
  1015. return (pLink->pbport.pbdevicetype == PBDT_Pad);
  1016. }
  1017. #if 0
  1018. //----------------------------------------------------------------------------
  1019. // Function: IsNt40Machine
  1020. //
  1021. // Returns whether the given machine is running nt40
  1022. //----------------------------------------------------------------------------
  1023. DWORD
  1024. IsNt40Machine (
  1025. IN PWCHAR pszServer,
  1026. OUT PBOOL pbIsNt40)
  1027. {
  1028. DWORD dwErr, dwType = REG_SZ, dwLength;
  1029. HKEY hkMachine, hkVersion;
  1030. WCHAR pszBuildNumber[64];
  1031. PWCHAR pszMachine = NULL;
  1032. //
  1033. // Validate and initialize
  1034. //
  1035. if (!pbIsNt40)
  1036. {
  1037. return ERROR_INVALID_PARAMETER;
  1038. }
  1039. *pbIsNt40 = FALSE;
  1040. do
  1041. {
  1042. // Format the machine name
  1043. if ( (pszServer) && (wcslen(pszServer) > 0) )
  1044. {
  1045. dwLength = wcslen( pszServer ) + 3;
  1046. pszMachine = (PWCHAR) Malloc ( dwLength * sizeof( WCHAR ) );
  1047. if (pszMachine == NULL)
  1048. {
  1049. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  1050. break;
  1051. }
  1052. if ( *pszMachine == L'\\' )
  1053. {
  1054. wcscpy( pszMachine, pszServer );
  1055. }
  1056. else
  1057. {
  1058. wcscpy( pszMachine, L"\\\\" );
  1059. wcscat( pszMachine, pszServer );
  1060. }
  1061. }
  1062. else
  1063. {
  1064. pszMachine = NULL;
  1065. }
  1066. //
  1067. // Connect to the remote server
  1068. //
  1069. dwErr = RegConnectRegistry(
  1070. pszMachine,
  1071. HKEY_LOCAL_MACHINE,
  1072. &hkMachine);
  1073. if ( dwErr != ERROR_SUCCESS )
  1074. {
  1075. break;
  1076. }
  1077. //
  1078. // Open the windows version key
  1079. //
  1080. dwErr = RegOpenKeyEx(
  1081. hkMachine,
  1082. c_szWinVersionPath,
  1083. 0,
  1084. KEY_ALL_ACCESS,
  1085. &hkVersion
  1086. );
  1087. if ( dwErr != NO_ERROR )
  1088. {
  1089. break;
  1090. }
  1091. //
  1092. // Read in the current version key
  1093. //
  1094. dwLength = sizeof(pszBuildNumber);
  1095. dwErr = RegQueryValueEx (
  1096. hkVersion,
  1097. c_szCurrentBuildNumber,
  1098. NULL,
  1099. &dwType,
  1100. (BYTE*)pszBuildNumber,
  1101. &dwLength
  1102. );
  1103. if (dwErr != NO_ERROR)
  1104. {
  1105. break;
  1106. }
  1107. if (lstrcmp (pszBuildNumber, c_szNt40BuildNumber) == 0)
  1108. {
  1109. *pbIsNt40 = TRUE;
  1110. }
  1111. } while (FALSE);
  1112. // Cleanup
  1113. {
  1114. if ( hkVersion )
  1115. {
  1116. RegCloseKey( hkVersion );
  1117. }
  1118. if ( hkMachine )
  1119. {
  1120. RegCloseKey( hkMachine );
  1121. }
  1122. Free0( pszMachine );
  1123. }
  1124. return dwErr;
  1125. }
  1126. #endif
  1127. BOOL
  1128. PhoneNodeIsBlank(
  1129. IN DTLNODE* pNode )
  1130. // Returns true if the phone number in PBPHONE node 'pNode' is "blank",
  1131. // i.e. it contains no area code, phone number, or comment strings.
  1132. //
  1133. {
  1134. PBPHONE* pPhone;
  1135. pPhone = (PBPHONE* )DtlGetData( pNode );
  1136. ASSERT( pPhone );
  1137. if ((!pPhone->pszAreaCode || IsAllWhite( pPhone->pszAreaCode ))
  1138. && (!pPhone->pszPhoneNumber || IsAllWhite( pPhone->pszPhoneNumber ))
  1139. && (!pPhone->pszComment || IsAllWhite( pPhone->pszComment )))
  1140. {
  1141. return TRUE;
  1142. }
  1143. return FALSE;
  1144. }
  1145. BOOL
  1146. PhoneNumberDlg(
  1147. IN HWND hwndOwner,
  1148. IN BOOL fRouter,
  1149. IN OUT DTLLIST* pList,
  1150. IN OUT BOOL* pfCheck )
  1151. // Popup the phone number list dialog. 'HwndOwner' is the owner of the
  1152. // created dialog. 'FRouter' indicates router-style labels should be used
  1153. // rather than client-style. 'PList' is a list of Psz nodes containing
  1154. // the phone numbers. 'PfCheck' is the address that contains the initial
  1155. // "promote number" checkbox setting and which receives the value set by
  1156. // user.
  1157. //
  1158. // Returns true if user presses OK and succeeds, false if he presses
  1159. // Cancel or encounters an error.
  1160. //
  1161. {
  1162. DWORD sidHuntTitle;
  1163. DWORD sidHuntItemLabel;
  1164. DWORD sidHuntListLabel;
  1165. DWORD sidHuntCheckLabel;
  1166. //For whistler bug 227538
  1167. TCHAR *pszTitle = NULL, *pszItem = NULL, *pszList = NULL, *pszCheck = NULL;
  1168. DWORD dwErr = NO_ERROR;
  1169. TRACE( "PhoneNumberDlg" );
  1170. if (fRouter)
  1171. {
  1172. sidHuntTitle = SID_RouterHuntTitle;
  1173. sidHuntItemLabel = SID_RouterHuntItemLabel;
  1174. sidHuntListLabel = SID_RouterHuntListLabel;
  1175. sidHuntCheckLabel = SID_RouterHuntCheckLabel;
  1176. }
  1177. else
  1178. {
  1179. sidHuntTitle = SID_HuntTitle;
  1180. sidHuntItemLabel = SID_HuntItemLabel;
  1181. sidHuntListLabel = SID_HuntListLabel;
  1182. sidHuntCheckLabel = SID_HuntCheckLabel;
  1183. }
  1184. pszTitle = PszFromId( g_hinstDll, sidHuntTitle );
  1185. pszItem = PszFromId( g_hinstDll, sidHuntItemLabel );
  1186. pszList = PszFromId( g_hinstDll, sidHuntListLabel );
  1187. pszCheck = PszFromId( g_hinstDll, sidHuntCheckLabel );
  1188. dwErr=ListEditorDlg(
  1189. hwndOwner,
  1190. pList,
  1191. pfCheck,
  1192. RAS_MaxPhoneNumber,
  1193. pszTitle,
  1194. pszItem,
  1195. pszList,
  1196. pszCheck,
  1197. NULL,
  1198. 0,
  1199. g_adwPnHelp,
  1200. 0,
  1201. NULL );
  1202. Free0( pszTitle );
  1203. Free0( pszItem );
  1204. Free0( pszList );
  1205. Free0( pszCheck );
  1206. return dwErr;
  1207. }
  1208. VOID
  1209. PositionDlg(
  1210. IN HWND hwndDlg,
  1211. IN BOOL fPosition,
  1212. IN LONG xDlg,
  1213. IN LONG yDlg )
  1214. // Positions the dialog 'hwndDlg' based on caller's API settings, where
  1215. // 'fPosition' is the RASxxFLAG_PositionDlg flag and 'xDlg' and 'yDlg' are
  1216. // the coordinates.
  1217. //
  1218. {
  1219. if (fPosition)
  1220. {
  1221. // Move it to caller's coordinates.
  1222. //
  1223. SetWindowPos( hwndDlg, NULL, xDlg, yDlg, 0, 0,
  1224. SWP_NOZORDER + SWP_NOSIZE );
  1225. UnclipWindow( hwndDlg );
  1226. }
  1227. else
  1228. {
  1229. // Center it on the owner window, or on the screen if none.
  1230. //
  1231. CenterWindow( hwndDlg, GetParent( hwndDlg ) );
  1232. }
  1233. }
  1234. LRESULT CALLBACK
  1235. PositionDlgStdCallWndProc(
  1236. int code,
  1237. WPARAM wparam,
  1238. LPARAM lparam )
  1239. // Standard Win32 CallWndProc hook callback that positions the next dialog
  1240. // to start in this thread at our standard offset relative to owner.
  1241. //
  1242. {
  1243. // Arrive here when any window procedure associated with our thread is
  1244. // called.
  1245. //
  1246. if (!wparam)
  1247. {
  1248. CWPSTRUCT* p = (CWPSTRUCT* )lparam;
  1249. // The message is from outside our process. Look for the MessageBox
  1250. // dialog initialization message and take that opportunity to position
  1251. // the dialog at the standard place relative to the calling dialog.
  1252. //
  1253. if (p->message == WM_INITDIALOG)
  1254. {
  1255. RECT rect;
  1256. HWND hwndOwner;
  1257. hwndOwner = GetParent( p->hwnd );
  1258. GetWindowRect( hwndOwner, &rect );
  1259. SetWindowPos( p->hwnd, NULL,
  1260. rect.left + DXSHEET, rect.top + DYSHEET,
  1261. 0, 0, SWP_NOZORDER + SWP_NOSIZE );
  1262. UnclipWindow( p->hwnd );
  1263. }
  1264. }
  1265. return 0;
  1266. }
  1267. TCHAR*
  1268. PszFromPhoneNumberList(
  1269. IN DTLLIST* pList )
  1270. // Returns the phone numbers in phone number list 'pList' in a comma
  1271. // string or NULL on error. It is caller's responsiblity to Free the
  1272. // returned string.
  1273. //
  1274. {
  1275. TCHAR* pszResult, *pszTemp;
  1276. DTLNODE* pNode;
  1277. DWORD cb;
  1278. const TCHAR* pszSeparator = TEXT(", ");
  1279. cb = (DtlGetNodes( pList ) *
  1280. (RAS_MaxPhoneNumber + lstrlen( pszSeparator )) + 1)
  1281. * sizeof(TCHAR);
  1282. pszResult = Malloc( cb );
  1283. if (!pszResult)
  1284. {
  1285. return NULL;
  1286. }
  1287. *pszResult = TEXT('\0');
  1288. for (pNode = DtlGetFirstNode( pList );
  1289. pNode;
  1290. pNode = DtlGetNextNode( pNode ))
  1291. {
  1292. TCHAR* psz = (TCHAR* )DtlGetData( pNode );
  1293. ASSERT( psz );
  1294. if (*pszResult)
  1295. lstrcat( pszResult, pszSeparator );
  1296. lstrcat( pszResult, psz );
  1297. }
  1298. pszTemp = Realloc( pszResult,
  1299. (lstrlen( pszResult ) + 1) * sizeof(TCHAR) );
  1300. ASSERT( pszTemp );
  1301. if (pszTemp)
  1302. {
  1303. pszResult = pszTemp;
  1304. }
  1305. return pszResult;
  1306. }
  1307. #if 0
  1308. LRESULT CALLBACK
  1309. SelectDesktopCallWndRetProc(
  1310. int code,
  1311. WPARAM wparam,
  1312. LPARAM lparam )
  1313. // Standard Win32 CallWndRetProc hook callback that makes "Desktop" the
  1314. // initial selection of the FileOpen "Look in" combo-box.
  1315. //
  1316. {
  1317. // Arrive here when any window procedure associated with our thread is
  1318. // called.
  1319. //
  1320. if (!wparam)
  1321. {
  1322. CWPRETSTRUCT* p = (CWPRETSTRUCT* )lparam;
  1323. // The message is from outside our process. Look for the MessageBox
  1324. // dialog initialization message and take that opportunity to set the
  1325. // "Look in:" combo box to the first item, i.e. "Desktop". FileOpen
  1326. // keys off CBN_CLOSEUP rather than CBN_SELCHANGE to update the
  1327. // "contents" listbox.
  1328. //
  1329. if (p->message == WM_INITDIALOG)
  1330. {
  1331. HWND hwndLbLookIn;
  1332. hwndLbLookIn = GetDlgItem( p->hwnd, cmb2 );
  1333. ComboBox_SetCurSel( hwndLbLookIn, 0 );
  1334. SendMessage( p->hwnd, WM_COMMAND,
  1335. MAKELONG( cmb2, CBN_CLOSEUP ), (LPARAM )hwndLbLookIn );
  1336. }
  1337. }
  1338. return 0;
  1339. }
  1340. #endif
  1341. //We want to get rid of the Icon resources from rasdlg, they take too much
  1342. //memory resource. instead, we retrieve them from netman.dll, if failed, we
  1343. //use the default one IID_Broadband gangz
  1344. //Also, for whistler bug 372078 364763 364876
  1345. //
  1346. HICON
  1347. GetCurrentIconEntryType(
  1348. IN DWORD dwType,
  1349. IN BOOL fSmall)
  1350. {
  1351. HICON hIcon = NULL;
  1352. DWORD dwSize, dwConnectionIcon;
  1353. HRESULT hr = E_FAIL;
  1354. NETCON_MEDIATYPE ncm;
  1355. HMODULE hNetshell = NULL;
  1356. HRESULT (WINAPI * pHrGetIconFromMediaType) (DWORD ,
  1357. NETCON_MEDIATYPE ,
  1358. NETCON_SUBMEDIATYPE ,
  1359. DWORD ,
  1360. DWORD ,
  1361. HICON *);
  1362. dwSize = fSmall ? 16 : 32;
  1363. switch (dwType)
  1364. {
  1365. case RASET_Direct:
  1366. {
  1367. ncm = NCM_DIRECT;
  1368. break;
  1369. }
  1370. case RASET_Vpn:
  1371. {
  1372. ncm = NCM_TUNNEL;
  1373. break;
  1374. }
  1375. case RASET_Broadband:
  1376. {
  1377. ncm = NCM_PPPOE;
  1378. break;
  1379. }
  1380. case RASET_Phone:
  1381. default:
  1382. {
  1383. ncm = NCM_PHONE;
  1384. break;
  1385. }
  1386. }
  1387. hNetshell = LoadLibrary(TEXT("netshell.dll"));
  1388. if( hNetshell )
  1389. {
  1390. pHrGetIconFromMediaType =(HRESULT (WINAPI*)(
  1391. DWORD ,
  1392. NETCON_MEDIATYPE ,
  1393. NETCON_SUBMEDIATYPE ,
  1394. DWORD ,
  1395. DWORD ,
  1396. HICON *) )GetProcAddress(
  1397. hNetshell,
  1398. "HrGetIconFromMediaType");
  1399. if ( NULL != pHrGetIconFromMediaType )
  1400. {
  1401. /*******************************************************************
  1402. ** dwConnectionIcon - (This is the little Computer part of the icon):
  1403. ** 0 - no connection overlay
  1404. ** 4 - Connection Icon with both lights off (Disabled status)
  1405. ** 5 - Connection Icon with left light on (Transmitting Data)
  1406. ** 6 - Connection Icon with right light on (Receiving Data)
  1407. ** 7 - Connection Icon with both lights on (Enabled status)
  1408. *********************************************************************/
  1409. dwConnectionIcon = 7;
  1410. hr = pHrGetIconFromMediaType(dwSize,
  1411. ncm,
  1412. NCSM_NONE,
  1413. 7,
  1414. 0,
  1415. &hIcon);
  1416. }
  1417. FreeLibrary( hNetshell );
  1418. }
  1419. if ( !SUCCEEDED(hr) || !hIcon)
  1420. {
  1421. ICONINFO iInfo;
  1422. HICON hTemp;
  1423. hTemp = LoadIcon( g_hinstDll, MAKEINTRESOURCE( IID_Broadband ) );
  1424. if(hTemp)
  1425. {
  1426. if( GetIconInfo(hTemp, &iInfo) )
  1427. {
  1428. hIcon = CreateIconIndirect(&iInfo);
  1429. }
  1430. }
  1431. }
  1432. return hIcon;
  1433. }
  1434. VOID
  1435. SetIconFromEntryType(
  1436. IN HWND hwndIcon,
  1437. IN DWORD dwType,
  1438. IN BOOL fSmall)
  1439. // Set the icon image of icon control 'dwType' to the image corresponding
  1440. // to the entry type 'dwType'.
  1441. //
  1442. {
  1443. HICON hIcon = NULL;
  1444. hIcon = GetCurrentIconEntryType( dwType, fSmall );
  1445. if (hIcon)
  1446. {
  1447. Static_SetIcon( hwndIcon, hIcon );
  1448. }
  1449. }
  1450. VOID
  1451. TweakTitleBar(
  1452. IN HWND hwndDlg )
  1453. // Adjust the title bar to include an icon if unowned and the modal frame
  1454. // if not. 'HwndDlg' is the dialog window.
  1455. //
  1456. {
  1457. if (GetParent( hwndDlg ))
  1458. {
  1459. LONG lStyle;
  1460. LONG lStyleAdd;
  1461. // Drop the system menu and go for the dialog look.
  1462. //
  1463. lStyleAdd = WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE;
  1464. lStyle = GetWindowLong( hwndDlg, GWL_EXSTYLE );
  1465. if (lStyle)
  1466. SetWindowLong( hwndDlg, GWL_EXSTYLE, lStyle | lStyleAdd );
  1467. }
  1468. else
  1469. {
  1470. // Stick a DUN1 icon in the upper left of the dialog, and more
  1471. // importantly on the task bar
  1472. //
  1473. // Whistler bug: 343455 RAS: Connection dialogs need to use new icons
  1474. //
  1475. //For whistler bug 381099 372078 gangz
  1476. //
  1477. HICON hIcon = NULL;
  1478. SendMessage( hwndDlg, WM_SETICON, ICON_SMALL,
  1479. (LPARAM )LoadIcon( g_hinstDll, MAKEINTRESOURCE( IID_Dun1 ) ) );
  1480. /*
  1481. //Use small Icon gangz
  1482. //Icon returned from GetCurrentIconEntryType() has to be destroyed after use
  1483. //In the future, Deonb will return a Icon for IID_Dun1 or dun1.ico for us.
  1484. hIcon = GetCurrentIconEntryType(RASET_Broadband , TRUE);
  1485. ASSERT(hIcon);
  1486. if(hIcon)
  1487. {
  1488. SendMessage( hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)(hIcon) );
  1489. SetProp( hwndDlg, TEXT("TweakTitleBar_Icon"), hIcon);
  1490. }
  1491. */
  1492. }
  1493. }
  1494. int CALLBACK
  1495. UnHelpCallbackFunc(
  1496. IN HWND hwndDlg,
  1497. IN UINT unMsg,
  1498. IN LPARAM lparam )
  1499. // A standard Win32 commctrl PropSheetProc. See MSDN documentation.
  1500. //
  1501. // Returns 0 always.
  1502. //
  1503. {
  1504. TRACE2( "UnHelpCallbackFunc(m=%d,l=%08x)",unMsg, lparam );
  1505. if (unMsg == PSCB_PRECREATE)
  1506. {
  1507. extern BOOL g_fNoWinHelp;
  1508. // Turn off context help button if WinHelp won't work. See
  1509. // common\uiutil\ui.c.
  1510. //
  1511. if (g_fNoWinHelp)
  1512. {
  1513. DLGTEMPLATE* pDlg = (DLGTEMPLATE* )lparam;
  1514. pDlg->style &= ~(DS_CONTEXTHELP);
  1515. }
  1516. }
  1517. return 0;
  1518. }