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.

118 lines
3.5 KiB

  1. //**********************************************************************
  2. // File name: timeout.cpp
  3. //
  4. // Implementation of idle timer
  5. //
  6. // Functions:
  7. //
  8. // Copyright (c) 1992 - 1998 Microsoft Corporation. All rights reserved.
  9. //**********************************************************************
  10. #include "pre.h"
  11. const DWORD cdwIdleMinsTimeout = 5; // 5 minute timeout after a page has been fetched
  12. INT_PTR CALLBACK DisconnectDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  13. {
  14. static HWND s_hwndSecs;
  15. static DWORD s_dwStartTicks;
  16. const DWORD cdwSecsTimeout = 30; // Timeout of 30 seconds
  17. const UINT cuTimerID = 812U;
  18. int iSecsRemaining;
  19. switch (uMsg)
  20. {
  21. case WM_INITDIALOG:
  22. // Start a one second timer
  23. s_hwndSecs = GetDlgItem(hwndDlg, IDC_SECONDS);
  24. SetTimer(hwndDlg, cuTimerID, 1000U, NULL);
  25. s_dwStartTicks = GetTickCount();
  26. return TRUE;
  27. case WM_TIMER:
  28. iSecsRemaining = cdwSecsTimeout - (int)(GetTickCount() - s_dwStartTicks) / 1000;
  29. if (iSecsRemaining <= 0)
  30. {
  31. KillTimer(hwndDlg, cuTimerID);
  32. EndDialog(hwndDlg, IDCANCEL);
  33. return TRUE;
  34. }
  35. if (NULL != s_hwndSecs)
  36. {
  37. TCHAR szSeconds[16];
  38. wsprintf(szSeconds, TEXT("%d"), iSecsRemaining);
  39. SetWindowText(s_hwndSecs, szSeconds);
  40. }
  41. return TRUE;
  42. case WM_COMMAND:
  43. // IDOK == Stay connected, IDCANCEL == Disconnect
  44. if (IDOK == wParam || IDCANCEL == wParam)
  45. {
  46. KillTimer(hwndDlg, cuTimerID);
  47. EndDialog(hwndDlg, wParam);
  48. }
  49. default:
  50. return 0;
  51. }
  52. }
  53. void CALLBACK IdleTimerProc (HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
  54. {
  55. KillTimer(NULL, gpWizardState->nIdleTimerID);
  56. gpWizardState->nIdleTimerID = 0;
  57. if (gpWizardState->hWndMsgBox)
  58. EnableWindow(gpWizardState->hWndMsgBox,FALSE);
  59. int iResult = (int)DialogBox(ghInstanceResDll,
  60. MAKEINTRESOURCE(IDD_AUTODISCONNECT),
  61. gpWizardState->hWndWizardApp,
  62. DisconnectDlgProc);
  63. if (gpWizardState->hWndMsgBox)
  64. {
  65. EnableWindow(gpWizardState->hWndMsgBox,TRUE);
  66. SetActiveWindow(gpWizardState->hWndMsgBox);
  67. }
  68. if (iResult == IDCANCEL)
  69. {
  70. // Disconnect, and setup so that the user goes to the dial error page
  71. gpWizardState->pRefDial->DoHangup();
  72. // Simulate the pressing of the NEXT button. The ISPPAGE will see that
  73. // bAutoDisconnected is TRUE, and automatically goto the server error page
  74. gpWizardState->bAutoDisconnected = TRUE;
  75. PropSheet_PressButton(gpWizardState->hWndWizardApp,PSBTN_NEXT);
  76. }
  77. else
  78. {
  79. gpWizardState->nIdleTimerID = SetTimer(NULL, 0, cdwIdleMinsTimeout * 60 * 1000, IdleTimerProc);
  80. }
  81. }
  82. void StartIdleTimer()
  83. {
  84. // Start the 5 min inactivity timer
  85. if (gpWizardState->nIdleTimerID)
  86. {
  87. KillTimer(NULL, gpWizardState->nIdleTimerID);
  88. }
  89. gpWizardState->nIdleTimerID = SetTimer(NULL, 0, cdwIdleMinsTimeout * 60 * 1000, IdleTimerProc);
  90. }
  91. void KillIdleTimer()
  92. {
  93. if (gpWizardState->nIdleTimerID)
  94. {
  95. KillTimer(NULL, gpWizardState->nIdleTimerID);
  96. gpWizardState->nIdleTimerID = 0;
  97. }
  98. }