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.

1004 lines
26 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 = NO_ERROR;
  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, dwErrTmp = NO_ERROR;
  306. DWORD cb = sizeof(dwFlag);
  307. dwErrTmp = g_pRasGetAutodialParam(
  308. RASADP_LoginSessionDisable,
  309. &dwFlag,
  310. &cb );
  311. // For whistler 522872
  312. if( NO_ERROR != dwErrTmp )
  313. {
  314. dwFlag = FALSE;
  315. }
  316. CheckDlgButton(
  317. hwnd,
  318. CID_AQ_CB_DisableThisSession,
  319. (BOOL )dwFlag );
  320. }
  321. }
  322. return TRUE;
  323. }
  324. case CID_AQ_PB_Dial:
  325. case CID_AQ_PB_DoNotDial:
  326. {
  327. TRACE( "(No)Dial pressed" );
  328. if (wId == CID_AQ_PB_Dial && pInfo)
  329. {
  330. iSelected =
  331. ListView_GetSelectionMark(pInfo->hwndAqLvConnections);
  332. // If user does not select a connection, then default to the
  333. // first one. Alternatively, an error popup could be
  334. // raised here but that is annoying.
  335. //
  336. if (iSelected == -1)
  337. {
  338. iSelected = 0;
  339. }
  340. // Get the name of the selected connection
  341. //
  342. if (pInfo)
  343. {
  344. ListView_GetItemText(
  345. pInfo->hwndAqLvConnections,
  346. iSelected,
  347. 0,
  348. pInfo->pArgs->pszNewEntry,
  349. RAS_MaxEntryName + 1);
  350. }
  351. }
  352. //For whistler bug 357164 gangz
  353. // Save the "disable current session" checkbox,
  354. //
  355. {
  356. DWORD dwFlag = (DWORD )IsDlgButtonChecked(
  357. hwnd,
  358. CID_AQ_CB_DisableThisSession );
  359. dwErr = g_pRasSetAutodialParam(
  360. RASADP_LoginSessionDisable,
  361. &dwFlag,
  362. sizeof(dwFlag) );
  363. }
  364. EndDialog( hwnd, (wId == CID_AQ_PB_Dial) ? NO_ERROR : ERROR_CANCELLED );
  365. return TRUE;
  366. }
  367. case IDCANCEL:
  368. {
  369. TRACE( "Cancel pressed" );
  370. EndDialog( hwnd, ERROR_CANCELLED );
  371. return TRUE;
  372. }
  373. }
  374. return FALSE;
  375. }
  376. // Fills the list view of connections and selects the appropriate one to
  377. // dial
  378. //
  379. DWORD
  380. AqFillListView(
  381. IN AQINFO* pInfo)
  382. {
  383. DWORD dwErr = NO_ERROR, cb, cEntries = 0, i;
  384. RASENTRYNAME ren, *pRasEntryNames = NULL;
  385. LVITEM lvItem;
  386. INT iIndex, iSelect = 0;
  387. do
  388. {
  389. // Enumerate entries across all phonebooks.
  390. //
  391. cb = ren.dwSize = sizeof(RASENTRYNAME);
  392. ASSERT( g_pRasEnumEntries );
  393. dwErr = g_pRasEnumEntries(NULL, NULL, &ren, &cb, &cEntries);
  394. // If there are no entries, then we return an error to signal that
  395. // there is no point to the dialog.
  396. //
  397. if ((SUCCESS == dwErr) && (0 == cEntries))
  398. {
  399. dwErr = ERROR_CANCELLED;
  400. break;
  401. }
  402. // Allocate a buffer to receive the connections
  403. //
  404. if( ( (ERROR_BUFFER_TOO_SMALL == dwErr)
  405. || (SUCCESS == dwErr))
  406. && (cb >= sizeof(RASENTRYNAME)))
  407. {
  408. pRasEntryNames = (RASENTRYNAME *) Malloc(cb);
  409. if(NULL == pRasEntryNames)
  410. {
  411. // Nothing else can be done in this case
  412. //
  413. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  414. break;
  415. }
  416. pRasEntryNames->dwSize = sizeof(RASENTRYNAME);
  417. dwErr = g_pRasEnumEntries(NULL, NULL, pRasEntryNames, &cb, &cEntries);
  418. if ( NO_ERROR != dwErr )
  419. {
  420. break;
  421. }
  422. }
  423. else
  424. {
  425. break;
  426. }
  427. // Initialize the list view
  428. //
  429. if (ListView_GetItemCount( pInfo->hwndAqLvConnections ) == 0)
  430. {
  431. // Add a single column exactly wide enough to fully display
  432. // the widest member of the list.
  433. //
  434. LV_COLUMN col;
  435. ZeroMemory( &col, sizeof(col) );
  436. col.mask = LVCF_FMT;
  437. col.fmt = LVCFMT_LEFT;
  438. ListView_InsertColumn( pInfo->hwndAqLvConnections, 0, &col );
  439. ListView_SetColumnWidth(
  440. pInfo->hwndAqLvConnections,
  441. 0,
  442. LVSCW_AUTOSIZE_USEHEADER );
  443. }
  444. else
  445. {
  446. ListView_DeleteAllItems( pInfo->hwndAqLvConnections );
  447. }
  448. // Fill the list view
  449. //
  450. for (i = 0; i < cEntries; i++)
  451. {
  452. ZeroMemory(&lvItem, sizeof(lvItem));
  453. lvItem.mask = LVIF_TEXT;
  454. lvItem.pszText = pRasEntryNames[i].szEntryName;
  455. lvItem.iItem = i;
  456. iIndex = ListView_InsertItem( pInfo->hwndAqLvConnections, &lvItem );
  457. if ((pInfo->pArgs->pszEntry) &&
  458. (wcsncmp(
  459. pInfo->pArgs->pszEntry,
  460. pRasEntryNames[i].szEntryName,
  461. sizeof(pRasEntryNames[i].szEntryName) / sizeof(WCHAR)) == 0))
  462. {
  463. iSelect = (iIndex != -1) ? iIndex : 0;
  464. }
  465. }
  466. }while (FALSE);
  467. // Select the appropriate connection
  468. //
  469. ListView_SetItemState(
  470. pInfo->hwndAqLvConnections,
  471. iSelect,
  472. LVIS_SELECTED | LVIS_FOCUSED,
  473. LVIS_SELECTED | LVIS_FOCUSED);
  474. // Cleanup
  475. {
  476. Free0(pRasEntryNames);
  477. }
  478. return dwErr;
  479. }
  480. BOOL
  481. AqInit(
  482. IN HWND hwndDlg,
  483. IN AQARGS* pArgs )
  484. // Called on WM_INITDIALOG. 'hwndDlg' is the handle of the owning window.
  485. // 'PArgs' is caller's arguments to the RAS API.
  486. //
  487. // Return false if focus was set, true otherwise, i.e. as defined for
  488. // WM_INITDIALOG.
  489. //
  490. {
  491. DWORD dwErr;
  492. AQINFO* pInfo;
  493. TRACE( "AqInit" );
  494. // Load the Rasapi32Dll so that we can enumerate connections
  495. // and set autodial properties
  496. //
  497. dwErr = LoadRasapi32Dll();
  498. if (dwErr != NO_ERROR)
  499. {
  500. ErrorDlg( hwndDlg, SID_OP_LoadDlg, dwErr, NULL );
  501. EndDialog( hwndDlg, FALSE);
  502. return TRUE;
  503. }
  504. // Allocate the dialog context block. Initialize minimally for proper
  505. // cleanup, then attach to the dialog window.
  506. //
  507. {
  508. pInfo = Malloc( sizeof(*pInfo) );
  509. if (!pInfo)
  510. {
  511. ErrorDlg( hwndDlg, SID_OP_LoadDlg, ERROR_NOT_ENOUGH_MEMORY, NULL );
  512. EndDialog( hwndDlg, FALSE );
  513. return TRUE;
  514. }
  515. ZeroMemory( pInfo, sizeof(*pInfo) );
  516. pInfo->pArgs = pArgs;
  517. pInfo->hwndDlg = hwndDlg;
  518. SetWindowLongPtr( hwndDlg, DWLP_USER, (ULONG_PTR )pInfo );
  519. TRACE( "AQ: Context set" );
  520. }
  521. pInfo->hwndStText = GetDlgItem( hwndDlg, CID_AQ_ST_Text );
  522. ASSERT( pInfo->hwndStText );
  523. pInfo->hwndAqPbNo = GetDlgItem( hwndDlg, CID_AQ_PB_DoNotDial );
  524. ASSERT( pInfo->hwndAqPbNo );
  525. pInfo->hwndAqPbSettings = GetDlgItem( hwndDlg, CID_AQ_PB_Settings );
  526. ASSERT( pInfo->hwndAqPbSettings );
  527. pInfo->hwndAqLvConnections = GetDlgItem( hwndDlg, CID_AQ_LV_Connections );
  528. ASSERT( pInfo->hwndAqLvConnections );
  529. // Fill in the listview of connections
  530. //
  531. dwErr = AqFillListView(pInfo);
  532. if (dwErr != NO_ERROR)
  533. {
  534. EndDialog(hwndDlg, dwErr);
  535. return TRUE;
  536. }
  537. // Fill in the argument in the explanatory text.
  538. //
  539. {
  540. TCHAR* pszTextFormat;
  541. TCHAR* pszText;
  542. TCHAR* apszArgs[ 1 ];
  543. pszTextFormat = PszFromId( g_hinstDll, SID_AQ_Text );
  544. if (pszTextFormat)
  545. {
  546. apszArgs[ 0 ] = pArgs->pszDestination;
  547. pszText = NULL;
  548. FormatMessage(
  549. FORMAT_MESSAGE_FROM_STRING
  550. | FORMAT_MESSAGE_ALLOCATE_BUFFER
  551. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  552. pszTextFormat, 0, 0, (LPTSTR )&pszText, 1,
  553. (va_list* )apszArgs );
  554. Free( pszTextFormat );
  555. if (pszText)
  556. {
  557. SetWindowText( pInfo->hwndStText, pszText );
  558. LocalFree( pszText );
  559. }
  560. }
  561. }
  562. // Display the finished window above all other windows. The window
  563. // position is set to "topmost" then immediately set to "not topmost"
  564. // because we want it on top but not always-on-top.
  565. //
  566. SetWindowPos(
  567. hwndDlg, HWND_TOPMOST, 0, 0, 0, 0,
  568. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
  569. CenterWindow( hwndDlg, GetParent( hwndDlg ) );
  570. ShowWindow( hwndDlg, SW_SHOW );
  571. SetWindowPos(
  572. hwndDlg, HWND_NOTOPMOST, 0, 0, 0, 0,
  573. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
  574. // for whistler bug 391195
  575. // Default is to connect, so set the focus on list box and default button
  576. // to connect
  577. //
  578. SetFocus( GetDlgItem( hwndDlg, CID_AQ_LV_Connections) ); //CID_AQ_PB_DoNotDial ) );
  579. //For whistler bug 357164 gangz
  580. // Initialize the "disable current session" checkbox
  581. //
  582. {
  583. DWORD dwFlag = FALSE, dwErrTmp = NO_ERROR;
  584. DWORD cb = sizeof(dwFlag);
  585. dwErrTmp = g_pRasGetAutodialParam(
  586. RASADP_LoginSessionDisable,
  587. &dwFlag,
  588. &cb );
  589. // For whistler 522872
  590. if( NO_ERROR != dwErrTmp)
  591. {
  592. dwFlag = FALSE;
  593. }
  594. CheckDlgButton(
  595. hwndDlg,
  596. CID_AQ_CB_DisableThisSession,
  597. (BOOL )dwFlag );
  598. }
  599. //Set up the timer for bug 336524 gangz
  600. //
  601. pInfo->pArgs->nIdTimer = 1;
  602. SetTimer( hwndDlg,
  603. pInfo->pArgs->nIdTimer,
  604. (pInfo->pArgs->dwTimeout) *1000,//in milliseconds
  605. NULL);
  606. return FALSE;
  607. }
  608. LVXDRAWINFO*
  609. AqLvCallback(
  610. IN HWND hwndLv,
  611. IN DWORD dwItem )
  612. // Enhanced list view callback to report drawing information. 'HwndLv' is
  613. // the handle of the list view control. 'DwItem' is the index of the item
  614. // being drawn.
  615. //
  616. // Returns the address of the draw information.
  617. //
  618. {
  619. // Use "full row select" and other recommended options.
  620. //
  621. // Fields are 'nCols', 'dxIndent', 'dwFlags', 'adwFlags[]'.
  622. //
  623. static LVXDRAWINFO info = { 1, 0, 0, { 0, 0 } };
  624. return &info;
  625. }
  626. BOOL
  627. AqNotify(
  628. HWND hwnd,
  629. int idCtrl,
  630. LPNMHDR pnmh)
  631. {
  632. AQINFO* pInfo = (AQINFO* )GetWindowLongPtr( hwnd, DWLP_USER );
  633. ASSERT(pInfo);
  634. ASSERT(pnmh);
  635. if(!pnmh || !pInfo)
  636. {
  637. return FALSE;
  638. }
  639. switch ( pnmh->code)
  640. {
  641. case LVN_ITEMACTIVATE:
  642. case LVN_KEYDOWN:
  643. case LVN_ITEMCHANGED:
  644. case LVN_ODSTATECHANGED:
  645. case LVN_COLUMNCLICK:
  646. case LVN_HOTTRACK:
  647. //re-set up the timer
  648. //
  649. ASSERT( pInfo->pArgs );
  650. if ( pInfo->pArgs->nIdTimer )
  651. {
  652. KillTimer( hwnd,
  653. pInfo->pArgs->nIdTimer);
  654. }
  655. break;
  656. default:
  657. break;
  658. }
  659. return FALSE;
  660. }
  661. VOID
  662. AqTerm(
  663. IN HWND hwndDlg )
  664. // Called on WM_DESTROY. 'HwndDlg' is that handle of the dialog window.
  665. //
  666. {
  667. AQINFO* pInfo = (AQINFO* )GetWindowLongPtr( hwndDlg, DWLP_USER );
  668. TRACE( "AqTerm" );
  669. if (pInfo)
  670. {
  671. ASSERT(pInfo->pArgs);
  672. if( pInfo->pArgs->nIdTimer )
  673. {
  674. KillTimer( hwndDlg,
  675. pInfo->pArgs->nIdTimer );
  676. }
  677. Free( pInfo );
  678. }
  679. }
  680. //Add the timer function for bug 336524
  681. //
  682. BOOL
  683. AqTimer(
  684. IN HWND hwndDlg )
  685. {
  686. AQINFO* pInfo = (AQINFO* )GetWindowLongPtr( hwndDlg, DWLP_USER );
  687. TRACE( "AqTimer" );
  688. pInfo->pArgs->nIdTimer = 0;
  689. EndDialog( hwndDlg, ERROR_CANCELLED );
  690. return TRUE;
  691. }
  692. //----------------------------------------------------------------------------
  693. // Auto-Dial Disable dialog
  694. // Listed alphabetically following API and dialog proc
  695. //----------------------------------------------------------------------------
  696. BOOL APIENTRY
  697. RasAutodialDisableDlgW(
  698. IN HWND hwndOwner )
  699. // Private external entry point to popup the Auto-Dial Disable Query, i.e.
  700. // the "Attempt failed Do you want to disable auto-dial for this
  701. // location?" dialog. 'HwndOwner' is the owning window or NULL if none.
  702. //
  703. // Returns true if user chose to disable, false otherwise.
  704. //
  705. {
  706. INT_PTR nStatus;
  707. TRACE( "RasAutodialDisableDlgA" );
  708. nStatus =
  709. (BOOL )DialogBoxParam(
  710. g_hinstDll,
  711. MAKEINTRESOURCE( DID_DQ_DisableAutoDialQuery ),
  712. hwndOwner,
  713. DqDlgProc,
  714. (LPARAM )0 );
  715. if (nStatus == -1)
  716. {
  717. ErrorDlg( hwndOwner, SID_OP_LoadDlg, ERROR_UNKNOWN, NULL );
  718. nStatus = FALSE;
  719. }
  720. return (BOOL )nStatus;
  721. }
  722. BOOL APIENTRY
  723. RasAutodialDisableDlgA(
  724. IN HWND hwndOwner )
  725. {
  726. return RasAutodialDisableDlgW( hwndOwner );
  727. }
  728. INT_PTR CALLBACK
  729. DqDlgProc(
  730. IN HWND hwnd,
  731. IN UINT unMsg,
  732. IN WPARAM wparam,
  733. IN LPARAM lparam )
  734. // DialogProc callback for the Auto-Dial Query dialog. Parameters and
  735. // return value are as described for standard windows 'DialogProc's.
  736. //
  737. {
  738. #if 0
  739. TRACE4( "AqDlgProc(h=$%x,m=$%x,w=$%x,l=$%x)",
  740. (DWORD )hwnd, (DWORD )unMsg, (DWORD )wparam, (DWORD )lparam );
  741. #endif
  742. switch (unMsg)
  743. {
  744. case WM_INITDIALOG:
  745. {
  746. return DqInit( hwnd );
  747. }
  748. case WM_COMMAND:
  749. {
  750. return DqCommand(
  751. hwnd, HIWORD( wparam ), LOWORD( wparam ), (HWND )lparam );
  752. }
  753. }
  754. return FALSE;
  755. }
  756. BOOL
  757. DqCommand(
  758. IN HWND hwnd,
  759. IN WORD wNotification,
  760. IN WORD wId,
  761. IN HWND hwndCtrl )
  762. // Called on WM_COMMAND. 'Hwnd' is the dialog window. 'WNotification' is
  763. // the notification code of the command. 'wId' is the control/menu
  764. // identifier of the command. 'HwndCtrl' is the control window handle of
  765. // the command.
  766. //
  767. // Returns true if processed message, false otherwise.
  768. //
  769. {
  770. DWORD dwErr;
  771. TRACE3( "DqCommand(n=%d,i=%d,c=$%x)",
  772. (DWORD )wNotification, (DWORD )wId, (ULONG_PTR )hwndCtrl );
  773. switch (wId)
  774. {
  775. case IDOK:
  776. {
  777. DWORD dwId;
  778. HLINEAPP hlineapp;
  779. TRACE( "Yes pressed" );
  780. // User chose to permanently disable auto-dial for the current
  781. // TAPI location.
  782. //
  783. dwErr = LoadRasapi32Dll();
  784. if (dwErr == 0)
  785. {
  786. hlineapp = 0;
  787. dwId = GetCurrentLocation( g_hinstDll, &hlineapp );
  788. ASSERT( g_pRasSetAutodialEnable );
  789. TRACE1( "RasSetAutodialEnable(%d)", dwId );
  790. dwErr = g_pRasSetAutodialEnable( dwId, FALSE );
  791. TRACE1( "RasSetAutodialEnable=%d", dwErr );
  792. TapiShutdown( hlineapp );
  793. }
  794. if (dwErr != 0)
  795. {
  796. ErrorDlg( hwnd, SID_OP_SetADialInfo, dwErr, NULL );
  797. }
  798. EndDialog( hwnd, TRUE );
  799. return TRUE;
  800. }
  801. case IDCANCEL:
  802. {
  803. TRACE( "No or cancel pressed" );
  804. EndDialog( hwnd, FALSE );
  805. return TRUE;
  806. }
  807. }
  808. return FALSE;
  809. }
  810. BOOL
  811. DqInit(
  812. IN HWND hwndDlg )
  813. // Called on WM_INITDIALOG. 'hwndDlg' is the handle of the owning window.
  814. //
  815. // Return false if focus was set, true otherwise, i.e. as defined for
  816. // WM_INITDIALOG.
  817. //
  818. {
  819. TRACE( "DqInit" );
  820. // Display the finished window above all other windows. The window
  821. // position is set to "topmost" then immediately set to "not topmost"
  822. // because we want it on top but not always-on-top.
  823. //
  824. SetWindowPos(
  825. hwndDlg, HWND_TOPMOST, 0, 0, 0, 0,
  826. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
  827. CenterWindow( hwndDlg, GetParent( hwndDlg ) );
  828. ShowWindow( hwndDlg, SW_SHOW );
  829. SetWindowPos(
  830. hwndDlg, HWND_NOTOPMOST, 0, 0, 0, 0,
  831. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
  832. // Default is to not disable auto-dial.
  833. //
  834. SetFocus( GetDlgItem( hwndDlg, IDCANCEL ) );
  835. return FALSE;
  836. }