home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / DRAWCL.PAK / SUMMINFO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  9.2 KB  |  395 lines

  1. // summinfo.cpp : implementation of the CDrawDoc class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 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. #include <winnls.h>
  15.  
  16. #if !defined(_MAC)
  17. #include "drawcli.h"
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char BASED_CODE THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. #include <objbase.h>
  25.  
  26. // the following header redefines the DEFINE_GUID macro to actually allocate data
  27. #include <initguid.h>
  28. #ifndef INITGUID
  29. #define INITGUID
  30. #endif
  31.  
  32. // the DEFINE_GUID macro in the following header now allocates data
  33. #include "summinfo.h"
  34.  
  35. const OLECHAR szSummInfo[] = OLESTR("\005SummaryInformation");
  36.  
  37. #if defined(_UNICODE)
  38. LPCSTR tcstocs(LPCTSTR lpctStr) {                         // typed char (WCHAR) to CHAR
  39.     static CHAR strTemp[1024];
  40.     wcstombs(strTemp, lpctStr, 1024);
  41.     return strTemp;
  42. }
  43. #else // !defined(_UNICODE)
  44. #define tcstocs(lpctStr) (LPCSTR)(lpctStr)
  45. #endif
  46.  
  47. CSummInfo::CSummInfo()
  48. {
  49.     m_propSet.SetFormatVersion( 0 );
  50.     DWORD dwOSVer;
  51.     dwOSVer = (DWORD)MAKELONG(LOWORD(GetVersion()), 2);
  52.     m_propSet.SetOSVersion(dwOSVer);
  53.     m_propSet.SetClassID(FMTID_SummaryInformation);
  54.     m_pSection = m_propSet.AddSection(FMTID_SummaryInformation);
  55.     UINT cp = GetACP();
  56.     m_pSection->Set( PID_CODEPAGE, (void*)&cp, VT_I2);
  57.     SetTitle(_T(""));
  58.     SetSubject(_T(""));
  59.     SetAuthor(_T(""));
  60.     SetKeywords(_T(""));
  61.     SetComments(_T(""));
  62.     SetTemplate(_T(""));
  63.     SetLastAuthor(_T(""));
  64.     m_pSection->Set(PID_REVNUMBER, (void*)_T("0"), VT_LPSTR);
  65.     FILETIME zeroTime = {0L, 0L};
  66.     m_pSection->Set(PID_EDITTIME, (void*)&zeroTime, VT_FILETIME);
  67.     m_pSection->Set(PID_LASTPRINTED, (void*)&zeroTime, VT_FILETIME);
  68.     m_pSection->Set(PID_LASTSAVE_DTM, (void*)&zeroTime, VT_FILETIME);
  69.     m_pSection->Set(PID_CREATE_DTM, (void*)&zeroTime, VT_FILETIME);
  70.     SetNumPages(0);
  71.     SetNumWords(0);
  72.     SetNumChars(0);
  73.     SetAppname(_T(""));
  74.     SetSecurity(0);
  75. }
  76.  
  77. BOOL CSummInfo::SetTitle( LPCTSTR szTitle )
  78. {
  79.     return m_pSection->Set(PID_TITLE, (void*)tcstocs(szTitle), VT_LPSTR);
  80. }
  81.  
  82. CString CSummInfo::GetTitle()
  83. {
  84.     return CString((LPCSTR)m_pSection->Get(PID_TITLE)); 
  85. }
  86.  
  87. BOOL CSummInfo::SetSubject( LPCTSTR szSubject )
  88. {
  89.     return m_pSection->Set(PID_SUBJECT, (void*)tcstocs(szSubject), VT_LPSTR);
  90. }
  91.  
  92. CString CSummInfo::GetSubject()
  93. {
  94.     return CString((LPCSTR)m_pSection->Get(PID_SUBJECT)); 
  95. }
  96.  
  97. BOOL CSummInfo::SetAuthor( LPCTSTR szAuthor )
  98. {
  99.     return m_pSection->Set(PID_AUTHOR, (void*)tcstocs(szAuthor), VT_LPSTR);
  100. }
  101.  
  102. CString CSummInfo::GetAuthor()
  103. {
  104.     return CString((LPCSTR)m_pSection->Get(PID_AUTHOR)); 
  105. }
  106.  
  107. BOOL CSummInfo::SetKeywords( LPCTSTR szKeywords )
  108. {
  109.     return m_pSection->Set(PID_KEYWORDS, (void*)tcstocs(szKeywords), VT_LPSTR);
  110. }
  111.  
  112. CString CSummInfo::GetKeywords()
  113. {
  114.     return CString((LPCSTR)m_pSection->Get(PID_KEYWORDS)); 
  115. }
  116.  
  117. BOOL CSummInfo::SetComments( LPCTSTR szComments )
  118. {
  119.     return m_pSection->Set(PID_COMMENTS, (void*)tcstocs(szComments), VT_LPSTR);
  120. }
  121.  
  122. CString CSummInfo::GetComments()
  123. {
  124.     return CString((LPCSTR)m_pSection->Get(PID_COMMENTS)); 
  125. }
  126.  
  127. BOOL CSummInfo::SetTemplate( LPCTSTR szTemplate )
  128. {
  129.     return m_pSection->Set(PID_TEMPLATE, (void*)tcstocs(szTemplate), VT_LPSTR);
  130. }
  131.  
  132. CString CSummInfo::GetTemplate()
  133. {
  134.     return CString((LPCSTR)m_pSection->Get(PID_TEMPLATE)); 
  135. }
  136.  
  137. BOOL CSummInfo::SetLastAuthor( LPCTSTR szLastAuthor )
  138. {
  139.     return m_pSection->Set(PID_LASTAUTHOR, (void*)tcstocs(szLastAuthor), VT_LPSTR);
  140. }
  141.  
  142. CString CSummInfo::GetLastAuthor()
  143. {
  144.     return CString((LPCSTR)m_pSection->Get(PID_LASTAUTHOR)); 
  145. }
  146.  
  147. BOOL CSummInfo::IncrRevNum()
  148. {
  149.     ULONG count;
  150.     _stscanf((LPCTSTR)GetRevNum(), _T("%lu"), &count);
  151.     count++;
  152.     TCHAR buff[20];
  153.     _stprintf(buff, _T("%lu"), count);
  154.     return m_pSection->Set(PID_REVNUMBER, (void*)buff, VT_LPSTR);
  155. }
  156.  
  157. CString CSummInfo::GetRevNum()
  158. {
  159.     return CString((LPCSTR)m_pSection->Get(PID_REVNUMBER));
  160. }
  161.  
  162. void CSummInfo::StartEditTimeCount()
  163. {
  164.     FILETIME now;
  165.     CoFileTimeNow(&now);
  166.     startEdit = *(double*)&now;
  167. }
  168.  
  169. BOOL CSummInfo::AddCountToEditTime()
  170. {
  171.     FILETIME now;
  172.     CoFileTimeNow(&now);
  173.     double currTime = *(double*)&now;
  174.     double thisSession = currTime - startEdit;
  175.     double lastTotal = *(double*)m_pSection->Get(PID_EDITTIME);
  176.     double newTotal = lastTotal + thisSession;
  177.     return m_pSection->Set(PID_EDITTIME, (void*)&newTotal, VT_FILETIME);
  178. }
  179.  
  180. CString CSummInfo::GetEditTime()
  181. {
  182.     FILETIME now;
  183.     CoFileTimeNow(&now);
  184.     double currTime = *(double*)&now;
  185.     double thisSession = currTime - startEdit;
  186.     double lastTotal = *(double*)m_pSection->Get(PID_EDITTIME);
  187.     double newTotal = lastTotal + thisSession;
  188.     ULONG editMinutes = (ULONG)(newTotal/600000000);
  189.  
  190.     TCHAR buff[20];
  191.     _stprintf(buff, _T("%lu min"), editMinutes);
  192.     return CString(buff); 
  193. }
  194.  
  195. BOOL CSummInfo::RecordPrintDate()
  196. {
  197.     FILETIME printDate;
  198.     CoFileTimeNow(&printDate);
  199.     return m_pSection->Set(PID_LASTPRINTED, (void*)&printDate, VT_FILETIME);
  200. }
  201.  
  202. CString CSummInfo::GetLastPrintDate()
  203. {
  204.     FILETIME* pPrintDate = (FILETIME*)m_pSection->Get(PID_LASTPRINTED);
  205.     if ((pPrintDate == NULL) ||
  206.         ((pPrintDate->dwLowDateTime == 0L ) &&
  207.          (pPrintDate->dwHighDateTime == 0L)   ))
  208.         return CString(_T(""));
  209.     else
  210.     {
  211.         COleDateTime tempDate = *pPrintDate;
  212.         return tempDate.Format(); 
  213.     }
  214. }
  215.  
  216. BOOL CSummInfo::RecordCreateDate()
  217. {
  218.     FILETIME createDate;
  219.     CoFileTimeNow(&createDate);
  220.     return m_pSection->Set(PID_CREATE_DTM, (void*)&createDate, VT_FILETIME);
  221. }
  222.  
  223. CString CSummInfo::GetCreateDate()
  224. {
  225.     FILETIME* pCreateDate = (FILETIME*)m_pSection->Get(PID_CREATE_DTM); 
  226.     if ((pCreateDate == NULL) ||
  227.         ((pCreateDate->dwLowDateTime == 0L ) &&
  228.          (pCreateDate->dwHighDateTime == 0L)   ))
  229.         return CString(_T(""));
  230.     else
  231.     {
  232.         COleDateTime tempDate = *pCreateDate;
  233.         return tempDate.Format(); 
  234.     }
  235. }
  236.  
  237. BOOL CSummInfo::RecordSaveDate()
  238. {
  239.     FILETIME saveDate;
  240.     CoFileTimeNow(&saveDate);
  241.     return m_pSection->Set(PID_LASTSAVE_DTM, (void*)&saveDate, VT_FILETIME);
  242. }
  243.  
  244. CString CSummInfo::GetLastSaveDate()
  245. {
  246.     FILETIME *pSaveDate = (FILETIME*)m_pSection->Get(PID_LASTSAVE_DTM);
  247.     if ((pSaveDate == NULL) ||
  248.         ((pSaveDate->dwLowDateTime == 0L ) &&
  249.          (pSaveDate->dwHighDateTime == 0L)   ))
  250.         return CString(_T(""));
  251.     else
  252.     {
  253.         COleDateTime tempDate = *pSaveDate;
  254.         return tempDate.Format(); 
  255.     }
  256. }
  257.  
  258. BOOL CSummInfo::SetNumPages( ULONG nPages )
  259. {
  260.     return m_pSection->Set(PID_PAGECOUNT, (void*)&nPages, VT_I4);
  261. }
  262.  
  263. CString CSummInfo::GetNumPages()
  264. {
  265.     TCHAR buff[20];
  266.     ULONG* pNumPages = (ULONG*)m_pSection->Get(PID_PAGECOUNT);
  267.     if (pNumPages != NULL)
  268.     {
  269.         _stprintf(buff, _T("%lu"), *pNumPages); 
  270.         return CString(buff);
  271.     }
  272.     else
  273.         return CString(_T(""));
  274. }
  275.  
  276. BOOL CSummInfo::SetNumWords( ULONG nWords )
  277. {
  278.     return m_pSection->Set(PID_WORDCOUNT, (void*)&nWords, VT_I4);
  279. }
  280.  
  281. CString CSummInfo::GetNumWords()
  282. {
  283.     TCHAR buff[20];
  284.     ULONG* pNumWords = (ULONG*)m_pSection->Get(PID_WORDCOUNT);
  285.     if (pNumWords != NULL)
  286.     {
  287.         _stprintf(buff, _T("%lu"), *pNumWords); 
  288.         return CString(buff);
  289.     }
  290.     else
  291.         return CString(_T(""));
  292. }
  293.  
  294. BOOL CSummInfo::SetNumChars( ULONG nChars )
  295. {
  296.     return m_pSection->Set(PID_CHARCOUNT, (void*)&nChars, VT_I4);
  297. }
  298.  
  299. CString CSummInfo::GetNumChars()
  300. {
  301.     TCHAR buff[20];
  302.     ULONG* pNumChars = (ULONG*)m_pSection->Get(PID_CHARCOUNT);
  303.     if (pNumChars != NULL)
  304.     {
  305.         _stprintf(buff, _T("%lu"), *pNumChars); 
  306.         return CString(buff);
  307.     }
  308.     else
  309.         return CString(_T(""));
  310. }
  311.  
  312. BOOL CSummInfo::SetAppname( LPCTSTR szAppname )
  313. {
  314.     return m_pSection->Set(PID_APPNAME, (void*)tcstocs(szAppname), VT_LPSTR);
  315. }
  316.  
  317. CString CSummInfo::GetAppname()
  318. {
  319.     return CString((LPCSTR)m_pSection->Get(PID_APPNAME)); 
  320. }
  321.  
  322. BOOL CSummInfo::SetSecurity( ULONG nLevel )
  323. {
  324.     return m_pSection->Set(PID_SECURITY, (void*)&nLevel, VT_I4);
  325. }
  326.  
  327. CString CSummInfo::GetSecurity()
  328. {
  329.     TCHAR buff[20];
  330.     ULONG* pSecurity = (ULONG*)m_pSection->Get(PID_SECURITY);
  331.     if (pSecurity != NULL)
  332.     {
  333.         _stprintf(buff, _T("%lu"), *pSecurity); 
  334.         return CString(buff);
  335.     }
  336.     else
  337.         return CString(_T(""));
  338. }
  339.  
  340. BOOL CSummInfo::WriteToStorage( LPSTORAGE lpRootStg )
  341. {
  342.     if (lpRootStg != NULL)
  343.     {
  344.         LPSTREAM lpStream = NULL;
  345.         if (FAILED(lpRootStg->CreateStream( szSummInfo, 
  346.                    STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 
  347.                    0, 0, &lpStream )))
  348.         {
  349.             TRACE(_T("CreateStream failed\n"));
  350.             return FALSE;
  351.         }
  352.         else
  353.         {
  354.             if(!m_propSet.WriteToStream( lpStream ))
  355.             {
  356.                 TRACE(_T("WriteToStream failed\n"));
  357.                 return FALSE;
  358.             }
  359.             lpRootStg->Commit(STGC_DEFAULT);
  360.             lpStream->Release();
  361.             return TRUE;
  362.         }
  363.     }
  364.     return FALSE;
  365. }
  366.  
  367. BOOL CSummInfo::ReadFromStorage( LPSTORAGE lpRootStg )
  368. {
  369.     if (lpRootStg != NULL)
  370.     {
  371.         LPSTREAM lpStream = NULL;
  372.  
  373.         if (FAILED(lpRootStg->OpenStream( szSummInfo, 
  374.                    NULL, STGM_SHARE_EXCLUSIVE|STGM_READ, 
  375.                    0, &lpStream )))
  376.         {
  377.             TRACE(_T("OpenStream failed\n"));
  378.             return FALSE;
  379.         }
  380.         else
  381.         {
  382.             if (!m_propSet.ReadFromStream( lpStream ))
  383.             {
  384.                 TRACE(_T("ReadFromStream failed\n"));
  385.                 return FALSE;
  386.             }
  387.             lpStream->Release();
  388.             return TRUE;
  389.         }
  390.     }
  391.     return FALSE;
  392. }
  393.  
  394. #endif // !defined(_MAC)
  395.