home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / drawcli / propset.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  5.4 KB  |  195 lines

  1. // propset.h : interface of the CProperty, CPropertySection, and CPropertSet classes
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-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.  
  14. //  Property setting
  15.  
  16. typedef struct tagSECTIONHEADER
  17. {
  18.     DWORD       cbSection ;
  19.     DWORD       cProperties ;  // Number of props.
  20. } SECTIONHEADER, *LPSECTIONHEADER ;
  21.  
  22. typedef struct tagPROPERTYIDOFFSET
  23. {
  24.     DWORD       propertyID;
  25.     DWORD       dwOffset;
  26. } PROPERTYIDOFFSET, *LPPROPERTYIDOFFSET;
  27.  
  28. typedef struct tagPROPHEADER
  29. {
  30.     WORD        wByteOrder ;    // Always 0xFFFE
  31.     WORD        wFormat ;       // Always 0
  32.     DWORD       dwOSVer ;       // System version
  33.     CLSID       clsID ;         // Application CLSID
  34.     DWORD       cSections ;     // Number of sections (must be at least 1)
  35. } PROPHEADER, *LPPROPHEADER ;
  36.  
  37. typedef struct tagFORMATIDOFFSET
  38. {
  39.     GUID        formatID;
  40.     DWORD       dwOffset;
  41. } FORMATIDOFFSET, *LPFORMATIDOFFSET;
  42.  
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CProperty
  46.  
  47. class CProperty : public CObject
  48. {
  49.     friend class CPropertySet ;
  50.     friend class CPropertySection ;
  51.  
  52. public:
  53. // Construction
  54.     CProperty( void ) ;
  55.     CProperty( DWORD dwID, const LPVOID pValue, DWORD dwType ) ;
  56.  
  57. // Attributes
  58.     BOOL    Set( DWORD dwID, const LPVOID pValue, DWORD dwType ) ;
  59.     BOOL    Set( const LPVOID pValue, DWORD dwType ) ;
  60.     BOOL    Set( const LPVOID pValue ) ;
  61.     LPVOID  Get( DWORD* pcb ) ;     // Returns pointer to actual value
  62.     LPVOID  Get( void ) ;           // Returns pointer to actual value
  63.     DWORD   GetType( void ) ;       // Returns property type
  64.     void    SetType( DWORD dwType ) ;
  65.     DWORD   GetID( void ) ;
  66.     void    SetID( DWORD dwPropID ) ;
  67.  
  68.     LPVOID  GetRawValue( void ) ;   // Returns pointer internal value (may
  69.                                     // include size information)
  70. // Operations
  71.     BOOL    WriteToStream( IStream* pIStream ) ;
  72.     BOOL    ReadFromStream( IStream* pIStream ) ;
  73.  
  74. private:
  75.     DWORD       m_dwPropID ;
  76.     DWORD       m_dwType ;
  77.     LPVOID      m_pValue ;
  78.  
  79.     LPVOID  AllocValue(ULONG cb);
  80.     void    FreeValue();
  81.  
  82. public:
  83.     ~CProperty() ;
  84. } ;
  85.  
  86.  
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CPropertySection
  89.  
  90. class CPropertySection : public CObject
  91. {
  92.     friend class CPropertySet ;
  93.     friend class CProperty ;
  94.  
  95. public:
  96. // Construction
  97.     CPropertySection( void ) ;
  98.     CPropertySection( CLSID FormatID ) ;
  99.  
  100. // Attributes
  101.     CLSID   GetFormatID( void ) ;
  102.     void    SetFormatID( CLSID FormatID ) ;
  103.  
  104.     BOOL    Set( DWORD dwPropID, LPVOID pValue, DWORD dwType ) ;
  105.     BOOL    Set( DWORD dwPropID, LPVOID pValue ) ;
  106.     LPVOID  Get( DWORD dwPropID, DWORD* pcb ) ;
  107.     LPVOID  Get( DWORD dwPropID ) ;
  108.     void    Remove( DWORD dwPropID ) ;
  109.     void    RemoveAll() ;
  110.  
  111.     CProperty* GetProperty( DWORD dwPropID ) ;
  112.     void AddProperty( CProperty* pProp ) ;
  113.  
  114.     DWORD   GetSize( void ) ;
  115.     DWORD   GetCount( void ) ;
  116.     CObList* GetList( void ) ;
  117.  
  118.     BOOL    GetID( LPCTSTR pszName, DWORD* pdwPropID ) ;
  119.     BOOL    SetName( DWORD dwPropID, LPCTSTR pszName ) ;
  120.  
  121.     BOOL    SetSectionName( LPCTSTR pszName );
  122.     LPCTSTR GetSectionName( void );
  123.  
  124. // Operations
  125.     BOOL    WriteToStream( IStream* pIStream ) ;
  126.     BOOL    ReadFromStream( IStream* pIStream, LARGE_INTEGER liPropSet ) ;
  127.     BOOL    WriteNameDictToStream( IStream* pIStream ) ;
  128.     BOOL    ReadNameDictFromStream( IStream* pIStream ) ;
  129.  
  130. private:
  131. // Implementation
  132.     CLSID           m_FormatID ;
  133.     SECTIONHEADER   m_SH ;
  134.     // List of properties (CProperty)
  135.     CObList         m_PropList ;
  136.     // Dictionary of property names
  137.     CMapStringToPtr m_NameDict ;
  138.     CString         m_strSectionName;
  139.  
  140. public:
  141.     ~CPropertySection();
  142. } ;
  143.  
  144.  
  145. /////////////////////////////////////////////////////////////////////////////
  146. // CPropertySet
  147.  
  148. class CPropertySet : public CObject
  149. {
  150.     friend class CPropertySection ;
  151.     friend class CProperty ;
  152.  
  153. public:
  154. // Construction
  155.     CPropertySet( void ) ;
  156.     CPropertySet( CLSID clsID )  ;
  157.  
  158. // Attributes
  159.     BOOL    Set( CLSID FormatID, DWORD dwPropID, LPVOID pValue, DWORD dwType ) ;
  160.     BOOL    Set( CLSID FormatID, DWORD dwPropID, LPVOID pValue ) ;
  161.     LPVOID  Get( CLSID FormatID, DWORD dwPropID, DWORD* pcb ) ;
  162.     LPVOID  Get( CLSID FormatID, DWORD dwPropID ) ;
  163.     void    Remove( CLSID FormatID, DWORD dwPropID ) ;
  164.     void    Remove( CLSID FormatID ) ;
  165.     void    RemoveAll( ) ;
  166.  
  167.     CProperty* GetProperty( CLSID FormatID, DWORD dwPropID ) ;
  168.     void AddProperty( CLSID FormatID, CProperty* pProp ) ;
  169.     CPropertySection* GetSection( CLSID FormatID ) ;
  170.     CPropertySection* AddSection( CLSID FormatID ) ;
  171.     void AddSection( CPropertySection* psect ) ;
  172.  
  173.     WORD    GetByteOrder( void ) ;
  174.     WORD    GetFormatVersion( void ) ;
  175.     void    SetFormatVersion( WORD wFmtVersion ) ;
  176.     DWORD   GetOSVersion( void ) ;
  177.     void    SetOSVersion( DWORD dwOSVer ) ;
  178.     CLSID   GetClassID( void ) ;
  179.     void    SetClassID( CLSID clsid ) ;
  180.     DWORD   GetCount( void ) ;
  181.     CObList* GetList( void ) ;
  182.  
  183. // Operations
  184.     BOOL    WriteToStream( IStream* pIStream ) ;
  185.     BOOL    ReadFromStream( IStream* pIStream ) ;
  186.  
  187. // Implementation
  188. private:
  189.     PROPHEADER      m_PH ;
  190.     CObList         m_SectionList ;
  191.  
  192. public:
  193.     ~CPropertySet();
  194. } ;
  195.