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.

991 lines
25 KiB

  1. // Copyright (c) 1995, Microsoft Corporation, all rights reserved
  2. //
  3. // autodial.c
  4. // Remote Access Common Dialog APIs
  5. // Autodial APIs, currently private
  6. //
  7. // 11/19/95 Steve Cobb
  8. #include "rasdlgp.h"
  9. #include "shlobjp.h"
  10. //-----------------------------------------------------------------------------
  11. // Local datatypes
  12. //-----------------------------------------------------------------------------
  13. // Auto-dial query dialog argument block.
  14. //
  15. typedef struct
  16. _AQARGS
  17. {
  18. WCHAR* pszDestination;
  19. WCHAR* pszEntry;
  20. WCHAR* pszNewEntry; // points a buffer at least [RAS_MaxEntryName + 1]
  21. DWORD dwTimeout;
  22. UINT_PTR nIdTimer; //add for bug 336524 gangz
  23. }
  24. AQARGS;
  25. // Auto-dial query dialog context block.
  26. //
  27. typedef struct
  28. _AQINFO
  29. {
  30. // RAS API arguments.
  31. //
  32. AQARGS* pArgs;
  33. // Handle of this dialog and some of it's controls.
  34. //
  35. HWND hwndDlg;
  36. HWND hwndStText;
  37. HWND hwndAqPbNo;
  38. HWND hwndAqPbSettings;
  39. HWND hwndAqLvConnections;
  40. }
  41. AQINFO;
  42. //-----------------------------------------------------------------------------
  43. // External entry points
  44. //-----------------------------------------------------------------------------
  45. DWORD APIENTRY
  46. RasAutodialQueryDlgA(
  47. IN HWND hwndOwner,
  48. IN LPSTR lpszDestination,
  49. IN LPSTR lpszEntry,
  50. IN DWORD dwTimeout,
  51. OUT LPSTR lpszEntryUserSelected);
  52. BOOL APIENTRY
  53. RasAutodialDisableDlgA(
  54. IN HWND hwndOwner );
  55. DWORD
  56. APIENTRY
  57. RasUserPrefsDlgAutodial (
  58. HWND hwndParent);
  59. //-----------------------------------------------------------------------------
  60. // Local prototypes (alphabetically)
  61. //-----------------------------------------------------------------------------
  62. INT_PTR CALLBACK
  63. AqDlgProc(
  64. IN HWND hwnd,
  65. IN UINT unMsg,
  66. IN WPARAM wparam,
  67. IN LPARAM lparam );
  68. BOOL
  69. AqCommand(
  70. IN HWND hwnd,
  71. IN WORD wNotification,
  72. IN WORD wId,
  73. IN HWND hwndCtrl );
  74. BOOL
  75. AqInit(
  76. IN HWND hwndDlg,
  77. IN AQARGS* pArgs );
  78. LVXDRAWINFO*
  79. AqLvCallback(
  80. IN HWND hwndLv,
  81. IN DWORD dwItem );
  82. BOOL
  83. AqNotify(
  84. HWND hwnd,
  85. int idCtrl,
  86. LPNMHDR pnmh);
  87. VOID
  88. AqTerm(
  89. IN HWND hwndDlg );
  90. //Add the timer function for bug 336524
  91. //
  92. BOOL
  93. AqTimer(
  94. IN HWND hwndDlg );
  95. INT_PTR CALLBACK
  96. DqDlgProc(
  97. IN HWND hwnd,
  98. IN UINT unMsg,
  99. IN WPARAM wparam,
  100. IN LPARAM lparam );
  101. BOOL
  102. DqCommand(
  103. IN HWND hwnd,
  104. IN WORD wNotification,
  105. IN WORD wId,
  106. IN HWND hwndCtrl );
  107. BOOL
  108. DqInit(
  109. IN HWND hwndDlg );
  110. //-----------------------------------------------------------------------------
  111. // Auto-Dial Query dialog Listed alphabetically following API and dialog proc
  112. //-----------------------------------------------------------------------------
  113. DWORD APIENTRY
  114. RasAutodialQueryDlgW(
  115. IN HWND hwndOwner,
  116. IN LPWSTR lpszDestination,
  117. IN LPWSTR lpszEntry,
  118. IN DWORD dwTimeout,
  119. OUT PWCHAR lpszNewEntry)
  120. // Private external entry point to popup the Auto-Dial Query, i.e. the
  121. // "Cannot reach 'pszDestination'. Do you want to dial?" dialog.
  122. // 'HwndOwner' is the owning window or NULL if none. 'PszDestination' is
  123. // the network address that triggered the auto-dial for display.
  124. // 'DwTimeout' is the initial seconds on the countdown timer that ends the
  125. // dialog with a "do not dial" selection on timeout, or 0 for none.
  126. //
  127. // Returns true if user chooses to dial, false otherwise.
  128. //
  129. {
  130. INT_PTR nStatus;
  131. AQARGS args;
  132. DWORD dwErr = NO_ERROR;
  133. TRACE1( "RasAutodialQueryDlgW(t=%d)", dwTimeout );
  134. ZeroMemory(&args, sizeof(args));
  135. args.dwTimeout = dwTimeout;
  136. args.pszDestination = StrDup( lpszDestination );
  137. args.pszNewEntry = lpszNewEntry;
  138. if (lpszEntry)
  139. {
  140. args.pszEntry = StrDup( lpszEntry );
  141. }
  142. if (args.pszDestination == NULL)
  143. {
  144. Free0(args.pszEntry);
  145. return ERROR_NOT_ENOUGH_MEMORY;
  146. }
  147. nStatus =
  148. DialogBoxParam(
  149. g_hinstDll,
  150. MAKEINTRESOURCE( DID_AQ_AutoDialQuery ),
  151. hwndOwner,
  152. AqDlgProc,
  153. (LPARAM )&args );
  154. Free0( args.pszDestination );
  155. Free0( args.pszEntry );
  156. if (nStatus == -1)
  157. {
  158. dwErr = GetLastError();
  159. ErrorDlg( hwndOwner, SID_OP_LoadDlg, dwErr, NULL );
  160. nStatus = FALSE;
  161. }
  162. else
  163. {
  164. dwErr = (DWORD)nStatus;
  165. }
  166. return dwErr;
  167. }
  168. DWORD APIENTRY
  169. RasAutodialQueryDlgA(
  170. IN HWND hwndOwner,
  171. IN LPSTR lpszDestination,
  172. IN LPSTR lpszEntry,
  173. IN DWORD dwTimeout,
  174. OUT LPSTR lpszEntryUserSelected)
  175. // Private external entry point to popup the Auto-Dial Query, i.e. the
  176. // "Cannot reach 'pszDestination'. Do you want to dial?" dialog.
  177. // 'HwndOwner' is the owning window or NULL if none. 'PszDestination' is
  178. // the network address that triggered the auto-dial for display.
  179. // 'DwTimeout' is the initial seconds on the countdown timer that ends the
  180. // dialog with a "do not dial" selection on timeout, or 0 for none.
  181. //
  182. // Returns true if user chooses to dial, false otherwise.
  183. //
  184. {
  185. WCHAR* pszDestinationW = NULL, *pszEntryW = NULL;
  186. WCHAR pszNewEntryW[RAS_MaxEntryName + 1];
  187. BOOL dwErr = ERROR_NOT_ENOUGH_MEMORY;
  188. pszNewEntryW[0] = L'\0';
  189. pszDestinationW = StrDupWFromAUsingAnsiEncoding( lpszDestination );
  190. if ( lpszEntry )
  191. {
  192. pszEntryW = StrDupWFromAUsingAnsiEncoding ( lpszEntry );
  193. }
  194. if (NULL != pszDestinationW)
  195. {
  196. dwErr = RasAutodialQueryDlgW(
  197. hwndOwner,
  198. pszDestinationW,
  199. pszEntryW,
  200. dwTimeout,
  201. pszNewEntryW);
  202. Free( pszDestinationW );
  203. }
  204. Free0( pszEntryW );
  205. StrCpyAFromWUsingAnsiEncoding(
  206. lpszEntryUserSelected,
  207. pszNewEntryW,
  208. sizeof(pszNewEntryW) / sizeof(WCHAR));
  209. return dwErr;
  210. }
  211. INT_PTR CALLBACK
  212. AqDlgProc(
  213. IN HWND hwnd,
  214. IN UINT unMsg,
  215. IN WPARAM wparam,
  216. IN LPARAM lparam )
  217. // DialogProc callback for the Auto-Dial Query dialog. Parameters and
  218. // return value are as described for standard windows 'DialogProc's.
  219. //
  220. {
  221. if (ListView_OwnerHandler(
  222. hwnd, unMsg, wparam, lparam, AqLvCallback ))
  223. {
  224. return TRUE;
  225. }
  226. switch (unMsg)
  227. {
  228. case WM_INITDIALOG:
  229. {
  230. return AqInit( hwnd, (AQARGS* )lparam );
  231. }
  232. case WM_COMMAND:
  233. {
  234. return AqCommand(
  235. hwnd, HIWORD( wparam ), LOWORD( wparam ), (HWND )lparam );
  236. }
  237. case WM_NOTIFY:
  238. {
  239. return AqNotify(hwnd, (int)wparam, (LPNMHDR) lparam);
  240. }
  241. case WM_TIMER:
  242. {
  243. return AqTimer( hwnd );
  244. }
  245. case WM_DESTROY:
  246. {
  247. AqTerm( hwnd );
  248. break;
  249. }
  250. }
  251. return FALSE;
  252. }
  253. BOOL
  254. AqCommand(
  255. IN HWND hwnd,
  256. IN WORD wNotification,
  257. IN WORD wId,
  258. IN HWND hwndCtrl )
  259. // Called on WM_COMMAND. 'Hwnd' is the dialog window. 'WNotification' is
  260. // the notification code of the command. 'wId' is the control/menu
  261. // identifier of the command. 'HwndCtrl' is the control window handle of
  262. // the command.
  263. //
  264. // Returns true if processed message, false otherwise.
  265. //
  266. {
  267. DWORD dwErr;
  268. INT iSelected;
  269. AQINFO* pInfo = NULL;
  270. TRACE3( "AqCommand(n=%d,i=%d,c=$%x)",
  271. (DWORD )wNotification, (DWORD )wId, (ULONG_PTR )hwndCtrl );
  272. pInfo = (AQINFO* )GetWindowLongPtr( hwnd, DWLP_USER );
  273. switch (wId)
  274. {
  275. case CID_AQ_PB_Settings:
  276. {
  277. if (pInfo)
  278. {
  279. //For whistler bug 357164 gangz
  280. // Save the "disable current session" checkbox,
  281. //
  282. {
  283. DWORD dwFlag = (DWORD )IsDlgButtonChecked(
  284. hwnd,
  285. CID_AQ_CB_DisableThisSession );
  286. dwErr = g_pRasSetAutodialParam(
  287. RASADP_LoginSessionDisable,
  288. &dwFlag,
  289. sizeof(dwFlag) );
  290. }
  291. //For whistler bug 336524
  292. //Kill the timer
  293. ASSERT( pInfo->pArgs );
  294. if( pInfo->pArgs->nIdTimer )
  295. {
  296. KillTimer( hwnd,
  297. pInfo->pArgs->nIdTimer );
  298. pInfo->pArgs->nIdTimer = 0;
  299. }
  300. RasUserPrefsDlgAutodial(pInfo->hwndDlg);
  301. //For whistler bug 357164 gangz
  302. // Initialize the "disable current session" checkbox
  303. //
  304. {
  305. DWORD dwFlag = FALSE, dwErr = NO_ERROR;
  306. DWORD cb = sizeof(dwFlag);
  307. dwErr = g_pRasGetAutodialParam(
  308. RASADP_LoginSessionDisable,
  309. &dwFlag,
  310. &cb );
  311. CheckDlgButton(
  312. hwnd,
  313. CID_AQ_CB_DisableThisSession,
  314. (BOOL )dwFlag );
  315. }
  316. }
  317. return TRUE;
  318. }
  319. case CID_AQ_PB_Dial:
  320. case CID_AQ_PB_DoNotDial:
  321. {
  322. TRACE( "(No)Dial pressed" );
  323. if (wId == CID_AQ_PB_Dial && pInfo)
  324. {
  325. iSelected =
  326. ListView_GetSelectionMark(pInfo->hwndAqLvConnections);
  327. // If user does not select a connection, then default to the
  328. // first one. Alternatively, an error popup could be
  329. // raised here but that is annoying.
  330. //
  331. if (iSelected == -1)
  332. {
  333. iSelected = 0;
  334. }
  335. // Get the name of the selected connection
  336. //
  337. if (pInfo)
  338. {
  339. ListView_GetItemText(
  340. pInfo->hwndAqLvConnections,
  341. iSelected,
  342. 0,
  343. pInfo->pArgs->pszNewEntry,
  344. RAS_MaxEntryName + 1);
  345. }
  346. }
  347. //For whistler bug 357164 gangz
  348. // Save the "disable current session" checkbox,
  349. //
  350. {
  351. DWORD dwFlag = (DWORD )IsDlgButtonChecked(
  352. hwnd,
  353. CID_AQ_CB_DisableThisSession );
  354. dwErr = g_pRasSetAutodialParam(
  355. RASADP_LoginSessionDisable,
  356. &dwFlag,
  357. sizeof(dwFlag) );
  358. }
  359. EndDialog( hwnd, (wId == CID_AQ_PB_Dial) ? NO_ERROR : ERROR_CANCELLED );
  360. return TRUE;
  361. }
  362. case IDCANCEL:
  363. {
  364. TRACE( "Cancel pressed" );
  365. EndDialog( hwnd, ERROR_CANCELLED );
  366. return TRUE;
  367. }
  368. }
  369. return FALSE;
  370. }
  371. // Fills the list view of connections and selects the appropriate one to
  372. // dial
  373. //
  374. DWORD
  375. AqFillListView(
  376. IN AQINFO* pInfo)
  377. {
  378. DWORD dwErr = NO_ERROR, cb, cEntries = 0, i;
  379. RASENTRYNAME ren, *pRasEntryNames = NULL;
  380. LVITEM lvItem;
  381. INT iIndex, iSelect = 0;
  382. do
  383. {
  384. // Enumerate entries across all phonebooks.
  385. //
  386. cb = ren.dwSize = sizeof(RASENTRYNAME);
  387. ASSERT( g_pRasEnumEntries );
  388. dwErr = g_pRasEnumEntries(NULL, NULL, &ren, &cb, &cEntries);
  389. // If there are no entries, then we return an error to signal that
  390. // there is no point to the dialog.
  391. //
  392. if ((SUCCESS == dwErr) && (0 == cEntries))
  393. {
  394. dwErr = ERROR_CANCELLED;
  395. break;
  396. }
  397. // Allocate a buffer to receive the connections
  398. //
  399. if( ( (ERROR_BUFFER_TOO_SMALL == dwErr)
  400. || (SUCCESS == dwErr))
  401. && (cb >= sizeof(RASENTRYNAME)))
  402. {
  403. pRasEntryNames = (RASENTRYNAME *) Malloc(cb);
  404. if(NULL == pRasEntryNames)
  405. {
  406. // Nothing else can be done in this case
  407. //
  408. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  409. break;
  410. }
  411. pRasEntryNames->dwSize = sizeof(RASENTRYNAME);
  412. dwErr = g_pRasEnumEntries(NULL, NULL, pRasEntryNames, &cb, &cEntries);
  413. if ( NO_ERROR != dwErr )
  414. {
  415. break;
  416. }
  417. }
  418. else
  419. {
  420. break;
  421. }
  422. // Initialize the list view
  423. //
  424. if (ListView_GetItemCount( pInfo->hwndAqLvConnections ) == 0)
  425. {
  426. // Add a single column exactly wide enough to fully display
  427. // the widest member of the list.
  428. //
  429. LV_COLUMN col;
  430. ZeroMemory( &col, sizeof(col) );
  431. col.mask = LVCF_FMT;
  432. col.fmt = LVCFMT_LEFT;
  433. ListView_InsertColumn( pInfo->hwndAqLvConnections, 0, &col );
  434. ListView_SetColumnWidth(
  435. pInfo->hwndAqLvConnections,
  436. 0,
  437. LVSCW_AUTOSIZE_USEHEADER );
  438. }
  439. else
  440. {
  441. ListView_DeleteAllItems( pInfo->hwndAqLvConnections );
  442. }
  443. // Fill the list view
  444. //
  445. for (i = 0; i < cEntries; i++)
  446. {
  447. ZeroMemory(&lvItem, sizeof(lvItem));
  448. lvItem.mask = LVIF_TEXT;
  449. lvItem.pszText = pRasEntryNames[i].szEntryName;
  450. lvItem.iItem = i;
  451. iIndex = ListView_InsertItem( pInfo->hwndAqLvConnections, &lvItem );
  452. if ((pInfo->pArgs->pszEntry) &&
  453. (wcsncmp(
  454. pInfo->pArgs->pszEntry,
  455. pRasEntryNames[i].szEntryName,
  456. sizeof(pRasEntryNames[i].szEntryName) / sizeof(WCHAR)) == 0))
  457. {
  458. iSelect = (iIndex != -1) ? iIndex : 0;
  459. }
  460. }
  461. }while (FALSE);
  462. // Select the appropriate connection
  463. //
  464. ListView_SetItemState(
  465. pInfo->hwndAqLvConnections,
  466. iSelect,
  467. LVIS_SELECTED | LVIS_FOCUSED,
  468. LVIS_SELECTED | LVIS_FOCUSED);
  469. // Cleanup
  470. {
  471. Free0(pRasEntryNames);
  472. }
  473. return dwErr;
  474. }
  475. BOOL
  476. AqInit(
  477. IN HWND hwndDlg,
  478. IN AQARGS* pArgs )
  479. // Called on WM_INITDIALOG. 'hwndDlg' is the handle of the owning window.
  480. // 'PArgs' is caller's arguments to the RAS API.
  481. //
  482. // Return false if focus was set, true otherwise, i.e. as defined for
  483. // WM_INITDIALOG.
  484. //
  485. {
  486. DWORD dwErr;
  487. AQINFO* pInfo;
  488. TRACE( "AqInit" );
  489. // Load the Rasapi32Dll so that we can enumerate connections
  490. // and set autodial properties
  491. //
  492. dwErr = LoadRasapi32Dll();
  493. if (dwErr != NO_ERROR)
  494. {
  495. ErrorDlg( hwndDlg, SID_OP_LoadDlg, dwErr, NULL );
  496. EndDialog( hwndDlg, FALSE);
  497. return TRUE;
  498. }
  499. // Allocate the dialog context block. Initialize minimally for proper
  500. // cleanup, then attach to the dialog window.
  501. //
  502. {
  503. pInfo = Malloc( sizeof(*pInfo) );
  504. if (!pInfo)
  505. {
  506. ErrorDlg( hwndDlg, SID_OP_LoadDlg, ERROR_NOT_ENOUGH_MEMORY, NULL );
  507. EndDialog( hwndDlg, FALSE );
  508. return TRUE;
  509. }
  510. ZeroMemory( pInfo, sizeof(*pInfo) );
  511. pInfo->pArgs = pArgs;
  512. pInfo->hwndDlg = hwndDlg;
  513. SetWindowLongPtr( hwndDlg, DWLP_USER, (ULONG_PTR )pInfo );
  514. TRACE( "AQ: Context set" );
  515. }
  516. pInfo->hwndStText = GetDlgItem( hwndDlg, CID_AQ_ST_Text );
  517. ASSERT( pInfo->hwndStText );
  518. pInfo->hwndAqPbNo = GetDlgItem( hwndDlg, CID_AQ_PB_DoNotDial );
  519. ASSERT( pInfo->hwndAqPbNo );
  520. pInfo->hwndAqPbSettings = GetDlgItem( hwndDlg, CID_AQ_PB_Settings );
  521. ASSERT( pInfo->hwndAqPbSettings );
  522. pInfo->hwndAqLvConnections = GetDlgItem( hwndDlg, CID_AQ_LV_Connections );
  523. ASSERT( pInfo->hwndAqLvConnections );
  524. // Fill in the listview of connections
  525. //
  526. dwErr = AqFillListView(pInfo);
  527. if (dwErr != NO_ERROR)
  528. {
  529. EndDialog(hwndDlg, dwErr);
  530. return TRUE;
  531. }
  532. // Fill in the argument in the explanatory text.
  533. //
  534. {
  535. TCHAR* pszTextFormat;
  536. TCHAR* pszText;
  537. TCHAR* apszArgs[ 1 ];
  538. pszTextFormat = PszFromId( g_hinstDll, SID_AQ_Text );
  539. if (pszTextFormat)
  540. {
  541. apszArgs[ 0 ] = pArgs->pszDestination;
  542. pszText = NULL;
  543. FormatMessage(
  544. FORMAT_MESSAGE_FROM_STRING
  545. | FORMAT_MESSAGE_ALLOCATE_BUFFER
  546. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  547. pszTextFormat, 0, 0, (LPTSTR )&pszText, 1,
  548. (va_list* )apszArgs );
  549. Free( pszTextFormat );
  550. if (pszText)
  551. {
  552. SetWindowText( pInfo->hwndStText, pszText );
  553. LocalFree( pszText );
  554. }
  555. }
  556. }
  557. // Display the finished window above all other windows. The window
  558. // position is set to "topmost" then immediately set to "not topmost"
  559. // because we want it on top but not always-on-top.
  560. //
  561. SetWindowPos(
  562. hwndDlg, HWND_TOPMOST, 0, 0, 0, 0,
  563. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
  564. CenterWindow( hwndDlg, GetParent( hwndDlg ) );
  565. ShowWindow( hwndDlg, SW_SHOW );
  566. SetWindowPos(
  567. hwndDlg, HWND_NOTOPMOST, 0, 0, 0, 0,
  568. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
  569. // for whistler bug 391195
  570. // Default is to connect, so set the focus on list box and default button
  571. // to connect
  572. //
  573. SetFocus( GetDlgItem( hwndDlg, CID_AQ_LV_Connections) ); //CID_AQ_PB_DoNotDial ) );
  574. //For whistler bug 357164 gangz
  575. // Initialize the "disable current session" checkbox
  576. //
  577. {
  578. DWORD dwFlag = FALSE, dwErr = NO_ERROR;
  579. DWORD cb = sizeof(dwFlag);
  580. dwErr = g_pRasGetAutodialParam(
  581. RASADP_LoginSessionDisable,
  582. &dwFlag,
  583. &cb );
  584. CheckDlgButton(
  585. hwndDlg,
  586. CID_AQ_CB_DisableThisSession,
  587. (BOOL )dwFlag );
  588. }
  589. //Set up the timer for bug 336524 gangz
  590. //
  591. pInfo->pArgs->nIdTimer = 1;
  592. SetTimer( hwndDlg,
  593. pInfo->pArgs->nIdTimer,
  594. (pInfo->pArgs->dwTimeout) *1000,//in milliseconds
  595. NULL);
  596. return FALSE;
  597. }
  598. LVXDRAWINFO*
  599. AqLvCallback(
  600. IN HWND hwndLv,
  601. IN DWORD dwItem )
  602. // Enhanced list view callback to report drawing information. 'HwndLv' is
  603. // the handle of the list view control. 'DwItem' is the index of the item
  604. // being drawn.
  605. //
  606. // Returns the address of the draw information.
  607. //
  608. {
  609. // Use "full row select" and other recommended options.
  610. //
  611. // Fields are 'nCols', 'dxIndent', 'dwFlags', 'adwFlags[]'.
  612. //
  613. static LVXDRAWINFO info = { 1, 0, 0, { 0, 0 } };
  614. return &info;
  615. }
  616. BOOL
  617. AqNotify(
  618. HWND hwnd,
  619. int idCtrl,
  620. LPNMHDR pnmh)
  621. {
  622. AQINFO* pInfo = (AQINFO* )GetWindowLongPtr( hwnd, DWLP_USER );
  623. ASSERT(pInfo);
  624. ASSERT(pnmh);
  625. if(!pnmh || !pInfo)
  626. {
  627. return FALSE;
  628. }
  629. switch ( pnmh->code)
  630. {
  631. case LVN_ITEMACTIVATE:
  632. case LVN_KEYDOWN:
  633. case LVN_ITEMCHANGED:
  634. case LVN_ODSTATECHANGED:
  635. case LVN_COLUMNCLICK:
  636. case LVN_HOTTRACK:
  637. //re-set up the timer
  638. //
  639. ASSERT( pInfo->pArgs );
  640. if ( pInfo->pArgs->nIdTimer )
  641. {
  642. KillTimer( hwnd,
  643. pInfo->pArgs->nIdTimer);
  644. }
  645. break;
  646. default:
  647. break;
  648. }
  649. return FALSE;
  650. }
  651. VOID
  652. AqTerm(
  653. IN HWND hwndDlg )
  654. // Called on WM_DESTROY. 'HwndDlg' is that handle of the dialog window.
  655. //
  656. {
  657. AQINFO* pInfo = (AQINFO* )GetWindowLongPtr( hwndDlg, DWLP_USER );
  658. TRACE( "AqTerm" );
  659. if (pInfo)
  660. {
  661. ASSERT(pInfo->pArgs);
  662. if( pInfo->pArgs->nIdTimer )
  663. {
  664. KillTimer( hwndDlg,
  665. pInfo->pArgs->nIdTimer );
  666. }
  667. Free( pInfo );
  668. }
  669. }
  670. //Add the timer function for bug 336524
  671. //
  672. BOOL
  673. AqTimer(
  674. IN HWND hwndDlg )
  675. {
  676. AQINFO* pInfo = (AQINFO* )GetWindowLongPtr( hwndDlg, DWLP_USER );
  677. TRACE( "AqTimer" );
  678. pInfo->pArgs->nIdTimer = 0;
  679. EndDialog( hwndDlg, ERROR_CANCELLED );
  680. return TRUE;
  681. }
  682. //----------------------------------------------------------------------------
  683. // Auto-Dial Disable dialog
  684. // Listed alphabetically following API and dialog proc
  685. //----------------------------------------------------------------------------
  686. BOOL APIENTRY
  687. RasAutodialDisableDlgW(
  688. IN HWND hwndOwner )
  689. // Private external entry point to popup the Auto-Dial Disable Query, i.e.
  690. // the "Attempt failed Do you want to disable auto-dial for this
  691. // location?" dialog. 'HwndOwner' is the owning window or NULL if none.
  692. //
  693. // Returns true if user chose to disable, false otherwise.
  694. //
  695. {
  696. INT_PTR nStatus;
  697. TRACE( "RasAutodialDisableDlgA" );
  698. nStatus =
  699. (BOOL )DialogBoxParam(
  700. g_hinstDll,
  701. MAKEINTRESOURCE( DID_DQ_DisableAutoDialQuery ),
  702. hwndOwner,
  703. DqDlgProc,
  704. (LPARAM )0 );
  705. if (nStatus == -1)
  706. {
  707. ErrorDlg( hwndOwner, SID_OP_LoadDlg, ERROR_UNKNOWN, NULL );
  708. nStatus = FALSE;
  709. }
  710. return (BOOL )nStatus;
  711. }
  712. BOOL APIENTRY
  713. RasAutodialDisableDlgA(
  714. IN HWND hwndOwner )
  715. {
  716. return RasAutodialDisableDlgW( hwndOwner );
  717. }
  718. INT_PTR CALLBACK
  719. DqDlgProc(
  720. IN HWND hwnd,
  721. IN UINT unMsg,
  722. IN WPARAM wparam,
  723. IN LPARAM lparam )
  724. // DialogProc callback for the Auto-Dial Query dialog. Parameters and
  725. // return value are as described for standard windows 'DialogProc's.
  726. //
  727. {
  728. #if 0
  729. TRACE4( "AqDlgProc(h=$%x,m=$%x,w=$%x,l=$%x)",
  730. (DWORD )hwnd, (DWORD )unMsg, (DWORD )wparam, (DWORD )lparam );
  731. #endif
  732. switch (unMsg)
  733. {
  734. case WM_INITDIALOG:
  735. {
  736. return DqInit( hwnd );
  737. }
  738. case WM_COMMAND:
  739. {
  740. return DqCommand(
  741. hwnd, HIWORD( wparam ), LOWORD( wparam ), (HWND )lparam );
  742. }
  743. }
  744. return FALSE;
  745. }
  746. BOOL
  747. DqCommand(
  748. IN HWND hwnd,
  749. IN WORD wNotification,
  750. IN WORD wId,
  751. IN HWND hwndCtrl )
  752. // Called on WM_COMMAND. 'Hwnd' is the dialog window. 'WNotification' is
  753. // the notification code of the command. 'wId' is the control/menu
  754. // identifier of the command. 'HwndCtrl' is the control window handle of
  755. // the command.
  756. //
  757. // Returns true if processed message, false otherwise.
  758. //
  759. {
  760. DWORD dwErr;
  761. TRACE3( "DqCommand(n=%d,i=%d,c=$%x)",
  762. (DWORD )wNotification, (DWORD )wId, (ULONG_PTR )hwndCtrl );
  763. switch (wId)
  764. {
  765. case IDOK:
  766. {
  767. DWORD dwId;
  768. HLINEAPP hlineapp;
  769. TRACE( "Yes pressed" );
  770. // User chose to permanently disable auto-dial for the current
  771. // TAPI location.
  772. //
  773. dwErr = LoadRasapi32Dll();
  774. if (dwErr == 0)
  775. {
  776. hlineapp = 0;
  777. dwId = GetCurrentLocation( g_hinstDll, &hlineapp );
  778. ASSERT( g_pRasSetAutodialEnable );
  779. TRACE1( "RasSetAutodialEnable(%d)", dwId );
  780. dwErr = g_pRasSetAutodialEnable( dwId, FALSE );
  781. TRACE1( "RasSetAutodialEnable=%d", dwErr );
  782. TapiShutdown( hlineapp );
  783. }
  784. if (dwErr != 0)
  785. {
  786. ErrorDlg( hwnd, SID_OP_SetADialInfo, dwErr, NULL );
  787. }
  788. EndDialog( hwnd, TRUE );
  789. return TRUE;
  790. }
  791. case IDCANCEL:
  792. {
  793. TRACE( "No or cancel pressed" );
  794. EndDialog( hwnd, FALSE );
  795. return TRUE;
  796. }
  797. }
  798. return FALSE;
  799. }
  800. BOOL
  801. DqInit(
  802. IN HWND hwndDlg )
  803. // Called on WM_INITDIALOG. 'hwndDlg' is the handle of the owning window.
  804. //
  805. // Return false if focus was set, true otherwise, i.e. as defined for
  806. // WM_INITDIALOG.
  807. //
  808. {
  809. TRACE( "DqInit" );
  810. // Display the finished window above all other windows. The window
  811. // position is set to "topmost" then immediately set to "not topmost"
  812. // because we want it on top but not always-on-top.
  813. //
  814. SetWindowPos(
  815. hwndDlg, HWND_TOPMOST, 0, 0, 0, 0,
  816. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
  817. CenterWindow( hwndDlg, GetParent( hwndDlg ) );
  818. ShowWindow( hwndDlg, SW_SHOW );
  819. SetWindowPos(
  820. hwndDlg, HWND_NOTOPMOST, 0, 0, 0, 0,
  821. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
  822. // Default is to not disable auto-dial.
  823. //
  824. SetFocus( GetDlgItem( hwndDlg, IDCANCEL ) );
  825. return FALSE;
  826. }