home *** CD-ROM | disk | FTP | other *** search
/ Softwarová Záchrana 3 / Softwarova-zachrana-3.bin / pserv.cpl / pserv-2.4.exe / source / ServiceControlDialog.cpp < prev    next >
C/C++ Source or Header  |  2005-01-05  |  3KB  |  98 lines

  1. // ServiceControlDialog.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "pserv2.h"
  6. #include "ServiceControlDialog.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CServiceControlDialog dialog
  16. void DisplayErrorMessage(LPCTSTR lpszCaption, ...);
  17.  
  18. CServiceControlDialog::CServiceControlDialog(CService* pService, DWORD dwWaitHint, QUERYSTATEFN QueryStateFN, LPCTSTR lpszAction, CWnd* pParent /*=NULL*/)
  19.     :   CDialog(CServiceControlDialog::IDD, pParent),
  20.         m_dwWaitHint( dwWaitHint ),
  21.         m_nTimerID( 0 ),
  22.         m_QueryStateFN( QueryStateFN ),
  23.         m_lpszAction( lpszAction ),
  24.         m_pService( pService )
  25. {
  26.     //{{AFX_DATA_INIT(CServiceControlDialog)
  27.     m_strDescription = "";
  28.     //}}AFX_DATA_INIT
  29.     m_strDescription.Format(_T("About to %s %s"), lpszAction, (LPCTSTR) pService->m_strDisplayName);
  30. }
  31.  
  32.  
  33. void CServiceControlDialog::DoDataExchange(CDataExchange* pDX)
  34. {
  35.     CDialog::DoDataExchange(pDX);
  36.     //{{AFX_DATA_MAP(CServiceControlDialog)
  37.     DDX_Control(pDX, IDC_PROGRESS1, m_Progress);
  38.     DDX_Text(pDX, IDC_DESCRIPTION, m_strDescription);
  39.     //}}AFX_DATA_MAP
  40.     if( pDX->m_bSaveAndValidate )
  41.     {
  42.         CWnd::KillTimer(123);
  43.     }
  44.     else
  45.     {
  46.         ASSERT( ::IsWindow(m_hWnd));
  47.  
  48.         m_dwSecondsExpected = 2 + (m_dwWaitHint / 500);
  49.         m_dwSecondsElapsed = 0;
  50.         m_Progress.SetRange(0, (short) m_dwSecondsExpected );
  51.         m_Progress.SetStep(1);
  52.         m_Progress.StepIt();
  53.  
  54.         m_nTimerID = 123;
  55.         CWnd::SetTimer(m_nTimerID, 500, 0);
  56.     }
  57.     
  58. }
  59.  
  60.  
  61. BEGIN_MESSAGE_MAP(CServiceControlDialog, CDialog)
  62.     //{{AFX_MSG_MAP(CServiceControlDialog)
  63.     ON_WM_TIMER()
  64.     //}}AFX_MSG_MAP
  65. END_MESSAGE_MAP()
  66.  
  67.  
  68. void CServiceControlDialog::OnTimer(UINT nIDEvent) 
  69. {
  70.     ASSERT( nIDEvent == 123 );
  71.  
  72.     if( m_nTimerID != 0 )
  73.     {
  74.         m_dwSecondsElapsed++;
  75.         if( m_dwSecondsElapsed >= m_dwSecondsExpected )
  76.         {
  77.             m_nTimerID = 0;
  78.             DisplayErrorMessage(_T("ERROR, unable to %s %s in time"), m_lpszAction, (LPCTSTR) m_pService->m_strDisplayName ); 
  79.             EndDialog(IDCANCEL);
  80.         } 
  81.         SERVICE_STATE_TYPE sst = (m_pService->*m_QueryStateFN)();
  82.         if( sst == SERVICE_STATE_REACHED )
  83.         {
  84.             m_nTimerID = 0;
  85.             EndDialog(IDOK);
  86.         }
  87.         else if( sst == SERVICE_STATE_FAILED )
  88.         {
  89.             m_nTimerID = 0;
  90.             DisplayErrorMessage(_T("ERROR, unable to query status of %s"), (LPCTSTR) m_pService->m_strDisplayName );
  91.             EndDialog(IDCANCEL);
  92.         }
  93.         m_Progress.StepIt();
  94.     }
  95.  
  96.     CDialog::OnTimer(nIDEvent);
  97. }
  98.