home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK11 / MFC / SAMPLES / TESTSERV / NEWSERV.CP$ / newserv
Encoding:
Text File  |  1992-03-07  |  4.3 KB  |  187 lines

  1. // newserv.cpp : This file contains code which implements functions
  2. //  specific to the CNewServer class which is a derived class of
  3. //  COleServer.
  4. //
  5. // This is a part of the Microsoft Foundation Classes C++ library.
  6. // Copyright (C) 1992 Microsoft Corporation
  7. // All rights reserved.
  8. //
  9. // This source code is only intended as a supplement to the
  10. // Microsoft Foundation Classes Reference and Microsoft
  11. // QuickHelp documentation provided with the library.
  12. // See these sources for detailed information regarding the
  13. // Microsoft Foundation Classes product.
  14.  
  15. #include "testserv.h"
  16. #include "defs.h"
  17.  
  18. extern CStdioFile *pOleDump;
  19. extern void OutputLog (const char *pText);
  20.  
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. static CServDoc* GetAppDoc()
  24. {
  25.     CTestServer* pView = (CTestServer*)AfxGetApp()->m_pMainWnd;
  26.     if (pView == NULL)
  27.     {
  28.         return NULL;
  29.     }
  30.  
  31.     CServDoc* pDoc = pView->GetDocument();
  32.  
  33.     TRACE("The Server Doc is:  %x in GetAppDoc\n",pDoc);
  34.     if (pDoc == NULL)
  35.     {
  36.         return NULL;
  37.     }
  38.     
  39.     return pDoc;
  40. }
  41.  
  42.  
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CNewServer::OnOpenDoc(LPCSTR lpszDoc)
  46. //
  47.  
  48. #pragma warning(disable:4100)
  49. // C4100 is 'unused formal parameter' warning
  50.  
  51. COleServerDoc*
  52. CNewServer::OnOpenDoc(LPCSTR lpszDoc)
  53. {
  54.     ASSERT(lpszDoc != NULL);
  55.  
  56.     CTestServer* pOwner = (CTestServer*)AfxGetApp()->m_pMainWnd;
  57.  
  58.     if (pOwner->m_pDoc && pOwner->m_pDoc->IsOpen())
  59.     {
  60.         return NULL;    // handle only one request at a time.
  61.     }
  62.  
  63.     CServDoc* pDoc = GetAppDoc();
  64.     
  65.     if (pDoc == NULL)
  66.     {
  67.         CTestServer* pOwner = (CTestServer*)AfxGetApp()->m_pMainWnd;
  68.         if (pOwner->m_bLogging)
  69.         {
  70.             OutputLog("NEWSERV.CPP::OnOpenDoc  GetAppDoc returned a NULL Pointer\n");
  71.         }
  72.     }
  73.     return pDoc;
  74. }
  75.  
  76. #pragma warning(default:4100)
  77.  
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CNewServer::OnCreateDoc(LPCSTR lpszClass, LPCSTR lpszDoc)
  81. //
  82. COleServerDoc*
  83. CNewServer::OnCreateDoc(LPCSTR lpszClass, LPCSTR lpszDoc)
  84. {
  85.     ASSERT(lpszClass != NULL);
  86.     ASSERT(lpszDoc != NULL);
  87.  
  88.     CTestServer* pOwner = (CTestServer*)AfxGetApp()->m_pMainWnd;
  89.  
  90.     if (pOwner->m_pDoc && pOwner->m_pDoc->IsOpen())
  91.     {
  92.         return NULL;    // handle only one request at a time.
  93.     }
  94.  
  95.     if (pOwner->m_bLogging)
  96.     {
  97.         OutputLog("CNewServer:  Now Receiving a Create Message With:\n");
  98.         char szBuffer[80];
  99.         wsprintf(szBuffer, "parameters (%Fs, %Fs)\n", lpszClass, lpszDoc);
  100.         OutputLog(szBuffer);
  101.     }
  102.  
  103.     CServDoc* pDoc = GetAppDoc();
  104.  
  105.     if (pDoc == NULL)
  106.     {
  107.         if (pOwner->m_bLogging)
  108.         {
  109.             OutputLog("NEWSERV.CPP::OnCreateDoc GetAppDoc returned a NULL pointer\n");
  110.         }
  111.     }
  112.     return pDoc;
  113. }
  114.  
  115.  
  116.  
  117.  
  118.  
  119. /////////////////////////////////////////////////////////////////////////////
  120. // CNewServer::OnEditDoc(LPCSTR lpszClass, LPCSTR lpszDoc)
  121. //
  122.  
  123. #pragma warning(disable:4100)
  124. // C4100 is 'unused formal parameter' warning
  125.  
  126. COleServerDoc*
  127. CNewServer::OnEditDoc(LPCSTR lpszClass, LPCSTR lpszDoc)
  128. {
  129.     ASSERT(lpszClass != NULL);
  130.     ASSERT(lpszDoc != NULL);
  131.     
  132.     CTestServer* pOwner = (CTestServer*)AfxGetApp()->m_pMainWnd;
  133.  
  134.     if (pOwner->m_pDoc && pOwner->m_pDoc->IsOpen())
  135.     {
  136.         return NULL;    // handle only one request at a time.
  137.     }
  138.  
  139.     CServDoc* pDoc = GetAppDoc();
  140.     
  141.     if (pDoc == NULL)
  142.     {
  143.         if (pOwner->m_bLogging)
  144.         {
  145.             OutputLog("NEWSERV.CPP::OnEditDoc  GetAppDoc returned a NULL pointer\n");
  146.         }
  147.     }
  148.     return pDoc;
  149. }
  150.  
  151. #pragma warning(default:4100)
  152.  
  153.  
  154.  
  155. /////////////////////////////////////////////////////////////////////////////
  156. // CNewServer::OnCreateDocFromTemplate(LPCSTR lpszClass,
  157. //              LPCSTR lpszDoc, LPCSTR lpszTemplate)
  158. //
  159. COleServerDoc* CNewServer::OnCreateDocFromTemplate(LPCSTR lpszClass,
  160.     LPCSTR lpszDoc, LPCSTR lpszTemplate)
  161. {
  162.     ASSERT(lpszClass != NULL);
  163.     ASSERT(lpszDoc != NULL);
  164.     ASSERT(lpszTemplate != NULL);
  165.  
  166.     CTestServer *pOwner = (CTestServer*)AfxGetApp()->m_pMainWnd;
  167.  
  168.     if (pOwner->m_pDoc && pOwner->m_pDoc->IsOpen())
  169.     {
  170.         return NULL;    // handle only one request at a time.
  171.     }
  172.  
  173.     if (pOwner->m_bLogging)
  174.     {
  175.         OutputLog("CNewServer::Received a CreateFromTemplate message\n");
  176.     }
  177.     
  178.  
  179.     return COleServer::OnCreateDocFromTemplate( lpszClass, lpszDoc,
  180.         lpszTemplate);
  181. }
  182.  
  183.  
  184.  
  185.  
  186. /////////////////////////////////////////////////////////////////////////////
  187.