home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / internet / httpsvr / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.5 KB  |  154 lines

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1997-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14.  
  15. #include "HttpSvr.h"
  16. #include "MainFrm.h"
  17. #include "ReqSock.h"
  18. #include "HttpDoc.h"
  19.  
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CMainFrame
  28.  
  29. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  30.  
  31. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  32.     //{{AFX_MSG_MAP(CMainFrame)
  33.     ON_WM_CREATE()
  34.     ON_WM_DESTROY()
  35.     ON_WM_TIMER()
  36.     //}}AFX_MSG_MAP
  37.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_UPTIME, OnUpdateUpTime)
  38. #ifdef IMPL_CGI
  39.     ON_MESSAGE(WSM_CGIDONE, OnCGIDone)
  40. #endif IMPL_CGI
  41. END_MESSAGE_MAP()
  42.  
  43. static UINT indicators[] =
  44. {
  45.     ID_SEPARATOR,           // status line indicator
  46.     ID_INDICATOR_UPTIME,
  47. };
  48.  
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CMainFrame construction/destruction
  51.  
  52. CMainFrame::CMainFrame()
  53. {
  54. }
  55.  
  56. CMainFrame::~CMainFrame()
  57. {
  58. }
  59.  
  60. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  61. {
  62.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  63.         return -1;
  64.  
  65.     if (!m_wndStatusBar.Create(this) ||
  66.         !m_wndStatusBar.SetIndicators(indicators,
  67.           sizeof(indicators)/sizeof(UINT)))
  68.     {
  69.         TRACE0("Failed to create status bar\n");
  70.         return -1;      // fail to create
  71.     }
  72.     // start the uptime counter....
  73.     CalcUpTime();
  74.     // kick off the uptime update timer....
  75.     m_uTimer = SetTimer( 1, 30000, NULL );
  76.  
  77.     return 0;
  78. }
  79.  
  80. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  81. {
  82.     // TODO: Modify the Window class or styles here by modifying
  83.     //  the CREATESTRUCT cs
  84.  
  85.     return CFrameWnd::PreCreateWindow(cs);
  86. }
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CMainFrame diagnostics
  90.  
  91. #ifdef _DEBUG
  92. void CMainFrame::AssertValid() const
  93. {
  94.     CFrameWnd::AssertValid();
  95. }
  96.  
  97. void CMainFrame::Dump(CDumpContext& dc) const
  98. {
  99.     CFrameWnd::Dump(dc);
  100. }
  101.  
  102. #endif //_DEBUG
  103.  
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CMainFrame message handlers
  106.  
  107.  
  108. void CMainFrame::OnUpdateUpTime(CCmdUI* pCmdUI)
  109. {
  110.     pCmdUI->Enable();
  111. }
  112.  
  113.  
  114. void CMainFrame::OnDestroy()
  115. {
  116.     CFrameWnd::OnDestroy();
  117.     if ( m_uTimer )
  118.         KillTimer( m_uTimer );
  119. }
  120.  
  121. void CMainFrame::OnTimer(UINT nIDEvent)
  122. {
  123.     CalcUpTime();
  124.     CFrameWnd::OnTimer(nIDEvent);
  125. }
  126.  
  127. void CMainFrame::CalcUpTime()
  128. {
  129.     CString strUpTime;
  130.     CHttpSvrDoc* pDoc = (CHttpSvrDoc*)GetActiveDocument();
  131.     // only canculate if we have a doc and it's listening....
  132.     if ( pDoc && pDoc->m_pListen )
  133.     {
  134.         CTime timeNow = CTime::GetCurrentTime();
  135.         // calculate uptime and set the status bar....
  136.         CTimeSpan upTime = timeNow - pDoc->m_timeStarted;
  137.         UINT uFmt = upTime.GetDays() > 0 ? IDS_UPTIME_DAYS : IDS_UPTIME_DAY;
  138.         strUpTime = upTime.Format( uFmt );
  139.     }
  140.     else
  141.         strUpTime.Format( IDS_UPTIME_START );
  142.  
  143.     m_wndStatusBar.SetPaneText( 1, strUpTime, TRUE );
  144. }
  145.  
  146. #ifdef IMPL_CGI
  147. LRESULT CMainFrame::OnCGIDone( WPARAM, LPARAM lParam )
  148. {
  149.     CRequestSocket* pReqSock = (CRequestSocket*)lParam;
  150.     pReqSock->CGIDone();
  151.     return 0;
  152. }
  153. #endif // IMPL_CGI
  154.