home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winui / shell / fileview / fvtext.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-12  |  9.0 KB  |  260 lines

  1. //THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  2. //ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  3. //THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright  1994-1996  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //    PROGRAM: FVTEXT.H    
  9. //
  10. //    PURPOSE:   Classes that implement the CFileViewer object for integration
  11. // with the Windows 95 Explorer.  Necessary modifications for a
  12. // custom viewer marked with MODIFY 
  13. //
  14. //    PLATFORMS:    Windows 95
  15. //
  16. //    SPECIAL INSTRUCTIONS: 
  17. //
  18. //DO NOT USE THESE GUIDS:  These are for this sample ONLY
  19. //File CLSID for the text compound file example:  this is nothing official.
  20. //Forward class references
  21.  
  22. DEFINE_GUID(CLSID_SampleTextFile, 0x00021116, 0, 0, 0xC0,0,0,0,0,0,0,0x46);
  23.  
  24. //MODIFY:  Define your custom FileViewer CLSID(s) here.
  25. DEFINE_GUID(CLSID_FileViewerText, 0x00021117, 0, 0, 0xC0,0,0,0,0,0,0,0x46);
  26.  
  27. #ifndef _FVTEXT_H_
  28. #define _FVTEXT_H_
  29.  
  30. class CImpIPersistFile;
  31. typedef class CImpIPersistFile *PIMPIPERSISTFILE;
  32.  
  33. class CImpIFileViewer;
  34. typedef class CImpIFileViewer *PIMPIFILEVIEWER;
  35.  
  36. //FVPROC.CPP
  37. //MODIFY:  Window procedures for frame and viewport windows
  38. long WINAPI FileViewerFrameProc(HWND, UINT, WPARAM, LPARAM);
  39.  
  40. //Extra bytes for frame
  41. #define CBWNDEXTRAFRAME             sizeof(LPVOID)
  42. #define FVWL_OBJECTPOINTER          0
  43.  
  44. /*
  45.  * MODIFY:  Change viewport window procedure and defintions
  46.  * to be specific to the file viewer in use.
  47.  */
  48. long WINAPI ViewportWndProc(HWND, UINT, WPARAM, LPARAM);
  49.  
  50. //Extra bytes for viewport
  51. #define CBWNDEXTRAVIEWPORT          sizeof(LPVOID)
  52. #define VPWL_OBJECTPOINTER          0
  53.  
  54.  
  55. BOOL APIENTRY AboutProc(HWND, UINT, WPARAM, LPARAM);
  56.  
  57.  
  58. //Child window IDs
  59. #define ID_TOOLBAR                  50
  60. #define ID_STATUSBAR                51
  61. #define ID_VIEWPORT                 52
  62.  
  63.  
  64. //Options for CFileViewer::FontChange.
  65. typedef enum
  66.     {
  67.     VIEWFONT_SELECT=0,
  68.     VIEWFONT_INCREASESIZE,
  69.     VIEWFONT_DECREASESIZE
  70.     } VIEWFONTOPTION;
  71.  
  72. /*
  73.  * Limits to font sizes for the Font dialog.  The increase and
  74.  * decrease buttons change the point size by different amounts
  75.  * (FONTSIZEDELTA*) depending on the size of the current font
  76.  * (where it falls in the FONTSIZETHRESHOLD*).  Note that these
  77.  * values have to be multiplied by logical_pixels_per_inch/72
  78.  * on the display to be accurate.  See CFileViewer::FontChange.
  79.  *
  80.  * Of course, there are better ways to do this that are font
  81.  * specific.  This way works well for stock fonts (Arial, Courier
  82.  * New, Times New Roman).
  83.  */
  84. #define FONTSIZETHRESHOLDMIN    4
  85. #define FONTSIZETHRESHOLDLOW    32
  86. #define FONTSIZETHRESHOLDMID    48
  87. #define FONTSIZETHRESHOLDMAX    120
  88. #define FONTSIZEDELTASMALL      2       //4 to 32pt
  89. #define FONTSIZEDELTAMEDIUM     8       //32 to 48pt
  90. #define FONTSIZEDELTALARGE      24      //48 to 120pt
  91.  
  92. //FVTEXT.CPP, FVINIT.CPP
  93. /*
  94.  * MODIFY:  Change this CFileViewer object to be more specific to
  95.  * your implementations.  Specific parts are listed below.
  96.  *
  97.  * The CFileViewer object is implemented in its own class with its own
  98.  * IUnknown to support aggregation.  It contains two interface
  99.  * implementation objects (CImpIPersistFile and CImpIFileViewer)
  100.  * to implement the externally exposed interfaces.
  101.  */
  102.  
  103. class CFileViewer : public IUnknown
  104.     {
  105.     //Make any contained interfaces your friends
  106.     friend class CImpIPersistFile;
  107.     friend class CImpIFileViewer;
  108.  
  109.     friend long WINAPI FileViewerFrameProc(HWND, UINT, WPARAM, LPARAM);
  110.     friend long WINAPI ViewportWndProc(HWND, UINT, WPARAM, LPARAM);
  111.  
  112.     protected:
  113.         //NOTE:  These members usually need no modification
  114.         ULONG               m_cRef;             //Object reference count
  115.  
  116.         LPUNKNOWN           m_pUnkOuter;        //Controlling unknown
  117.         HINSTANCE           m_hInst;            //Module instance
  118.         PFNDESTROYED        m_pfnDestroy;       //To call on closure
  119.         LPFILEVIEWERSITE m_lpfsi;       // file viewer site
  120.  
  121.         CLSID               m_clsID;            //CLSID of this FileViewer
  122.         LPSTR               m_pszPath;          //Path from IPersitFile::Load
  123.         DWORD               m_grfMode;          //Open mode for the file
  124.         BOOL                m_fLoadCalled;      //Load called already?
  125.         BOOL                m_fShowInit;        //ShowInitialize called?
  126.  
  127.         BOOL                m_fClassReg;        //RegisterClass work?
  128.         BOOL                m_fPostQuitMsg;     // Should destroy post quit
  129.         HWND                m_hWnd;             //Main window
  130.         HWND                m_hWndOld;          // Old Main window.
  131.         HWND                m_hWndToolbar;      //Child windows
  132.         HWND                m_hWndStatus;
  133.         HWND                m_hWndViewport;
  134.         HACCEL              m_hAccel;
  135.  
  136.         UINT                m_cyTools;          //Child window heights
  137.         UINT                m_cyStatus;
  138.  
  139.         BOOL                m_fToolsVisible;    //Visible child windows.
  140.         BOOL                m_fStatusVisible;
  141.  
  142.         PCStringTable       m_pST;              //Stringtable object
  143.         PCStatusHelper      m_pSH;              //For WM_MENUSELECT
  144.  
  145.         //Interface implementations
  146.         PIMPIPERSISTFILE    m_pIPersistFile;
  147.         PIMPIFILEVIEWER     m_pIFileViewer;
  148.         LPFVSHOWINFO        m_pvsi;
  149.  
  150.         /*
  151.          * MODIFY:  Change these to your own FileViewer specifics.
  152.          * The variables here are specific to text viewing.
  153.          */
  154.         HGLOBAL             m_hMemText;         //Loaded text.
  155.         HFONT               m_hFont;            //Current viewport font
  156.         int                 m_cyPPI;            //logical pix/inch
  157.         int                 m_xPos;             //Scroll positions
  158.         int                 m_yPos;
  159.  
  160.     protected:
  161.         BOOL                FInitFrameControls(void);
  162.         HRESULT             FileLoad(void);
  163.  
  164.         void                OnCommand(WORD, WORD, HWND);
  165.         void                ChildrenResize(void);
  166.         void                ViewportResize(void);
  167.         BOOL                FOpenAs(void);
  168.         LPSTR               PszToolTip(UINT);
  169.  
  170.         //MODIFY:  These may be irrelevant for a custom viewer
  171.         void                ViewportScrollSet(void);
  172.         void                FontChange(VIEWFONTOPTION);
  173.         void                ReplaceWindowModeChange(void);
  174.         BOOL                DropFiles(HDROP);
  175.  
  176.     public:
  177.         CFileViewer(LPUNKNOWN, HINSTANCE, PFNDESTROYED);
  178.         ~CFileViewer(void);
  179.  
  180.         HRESULT             Init(void);        //Called from IClassFactory::CreateInstance
  181.         LPSTR               String(UINT);      //inline--see FVTEXT.CPP
  182.         LPVOID              MemAlloc(ULONG);   //IMalloc helpers
  183.         void                MemFree(LPVOID);
  184.  
  185.         //IFileViewer implementataions (called from CImpIFileViewer)
  186.         STDMETHODIMP        FileShowInit(LPFILEVIEWERSITE lpfsi);
  187.         STDMETHODIMP        FileShow(LPFVSHOWINFO pvsi);
  188.         STDMETHODIMP        PrintTo(LPSTR, BOOL);
  189.  
  190.  
  191.         //Non-delegating object IUnknown interface
  192.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  193.         STDMETHODIMP_(ULONG) AddRef(void);
  194.         STDMETHODIMP_(ULONG) Release(void);
  195.     };
  196.  
  197. typedef CFileViewer * PCFileViewer;
  198.  
  199.  
  200.  
  201. /*
  202.  * Interface implementations for the CFileViewer object.
  203.  */
  204.  
  205. //IPERFILE.CPP
  206. class CImpIPersistFile : public IPersistFile
  207.     {
  208.     private:
  209.         PCFileViewer    m_pObj;         //Back pointer to object
  210.         LPUNKNOWN       m_pUnkOuter;    //Controlling unknown
  211.  
  212.     public:
  213.         CImpIPersistFile(PCFileViewer, LPUNKNOWN);
  214.         ~CImpIPersistFile(void);
  215.  
  216.         //IUnknown members that delegate to m_pUnkOuter.
  217.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  218.         STDMETHODIMP_(ULONG) AddRef(void);
  219.         STDMETHODIMP_(ULONG) Release(void);
  220.  
  221.         //IPersist members
  222.         STDMETHODIMP GetClassID(LPCLSID);
  223.  
  224.         //IPersistFile members
  225.         STDMETHODIMP IsDirty(void);
  226.         STDMETHODIMP Load(LPCOLESTR, DWORD);
  227.         STDMETHODIMP Save(LPCOLESTR, BOOL);
  228.         STDMETHODIMP SaveCompleted(LPCOLESTR);
  229.         STDMETHODIMP GetCurFile(LPOLESTR *);
  230.     };
  231.  
  232.  
  233.  
  234.  
  235. //IFILEVW.CPP
  236. class CImpIFileViewer : public IFileViewer
  237.     {
  238.     private:
  239.         PCFileViewer    m_pObj;         //Back pointer to object
  240.         LPUNKNOWN       m_pUnkOuter;    //Controlling unknown
  241.  
  242.     public:
  243.         CImpIFileViewer(PCFileViewer, LPUNKNOWN);
  244.         ~CImpIFileViewer(void);
  245.  
  246.         //IUnknown members that delegate to m_pUnkOuter.
  247.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  248.         STDMETHODIMP_(ULONG) AddRef(void);
  249.         STDMETHODIMP_(ULONG) Release(void);
  250.  
  251.         //IFileViewer members
  252.         STDMETHODIMP PrintTo(LPSTR, BOOL);
  253.         STDMETHODIMP ShowInitialize(LPFILEVIEWERSITE lpfsi);
  254.         STDMETHODIMP Show(LPFVSHOWINFO pvsi);
  255.     };
  256.  
  257.  
  258.  
  259. #endif //_FVTEXT_H_
  260.