home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap17 / patron / patron.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  6.6 KB  |  241 lines

  1. /*
  2.  * PATRON.H
  3.  * Patron Chapter 17
  4.  *
  5.  * Single include file that pulls in everything needed for other
  6.  * source files in the application.
  7.  *
  8.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  9.  *
  10.  * Kraig Brockschmidt, Microsoft
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #ifndef _PATRON_H_
  17. #define _PATRON_H_
  18.  
  19. #define INC_CLASSLIB
  20. #define INC_OLEUI
  21. //CHAPTER17MOD
  22. #define CHAPTER17
  23. //End CHAPTER17MOD
  24. #include <inole.h>
  25. #include "resource.h"
  26.  
  27. //Get editor window information
  28. #include "pages.h"
  29.  
  30.  
  31. /*
  32.  * UINT value such that adding one produces zero.  Portable to Win32.
  33.  * This is used to represent a non-existent zero-based UINT value
  34.  */
  35. #define NOVALUE                     ((UINT)-1)
  36.  
  37.  
  38. //PATRON.CPP:  Frame object that creates a main window
  39.  
  40. class CPatronFrame : public CFrame
  41.     {
  42.     private:
  43.         BOOL            m_fInitialized;     //OleInitialize worked
  44.         LPCLASSFACTORY  m_pIClassDataTran;  //For locking.
  45.  
  46.     protected:
  47.         //Overridable for creating a CPatronClient
  48.         virtual PCClient    CreateCClient(void);
  49.  
  50.         //CHAPTER17MOD
  51.         virtual BOOL        FMessageHook(HWND, UINT, WPARAM, LPARAM
  52.                                 , LRESULT *);
  53.         //End CHAPTER17MOD
  54.         virtual BOOL        RegisterAllClasses(void);
  55.         virtual UINT        CreateToolbar(void);
  56.         virtual LRESULT     OnCommand(HWND, WPARAM, LPARAM);
  57.  
  58.     public:
  59.         CPatronFrame(HINSTANCE, HINSTANCE, LPSTR, int);
  60.         virtual ~CPatronFrame(void);
  61.  
  62.         //Overrides
  63.         virtual BOOL        Init(PFRAMEINIT);
  64.  
  65.         virtual void        UpdateMenus(HMENU, UINT);
  66.         virtual void        UpdateToolbar(void);
  67.  
  68.     };
  69.  
  70.  
  71. typedef CPatronFrame *PCPatronFrame;
  72.  
  73.  
  74.  
  75.  
  76.  
  77. //CLIENT.CPP
  78.  
  79. /*
  80.  * The only reason we have a derived class here is to override
  81.  * CreateCDocument so we can create our own type as well as
  82.  * overriding NewDocument to perform one other piece of work once
  83.  * the document's been created.
  84.  */
  85.  
  86. class CPatronClient : public CClient
  87.     {
  88.     protected:
  89.         //Overridable for creating a new CDocument
  90.         virtual PCDocument CreateCDocument(void);
  91.  
  92.     public:
  93.         CPatronClient(HINSTANCE, PCFrame);
  94.         virtual ~CPatronClient(void);
  95.     };
  96.  
  97.  
  98. typedef CPatronClient *PCPatronClient;
  99.  
  100.  
  101.  
  102.  
  103. //DOCUMENT.CPP
  104.  
  105. //Constant ID for the pages window that lives in a document window
  106. #define ID_PAGES            723
  107.  
  108.  
  109. class CPatronDoc : public CDocument
  110.     {
  111.     //These need access to FQueryPasteFromData, PasteFromData
  112.     friend class CDropTarget;
  113.     friend class CDropSource;
  114.  
  115.     protected:
  116.         LONG            m_lVer;         //Loaded data version
  117.         PCPages         m_pPG;          //Pages window in us
  118.         LPSTORAGE       m_pIStorage;    //Root storage for document
  119.         BOOL            m_fPrintSetup;
  120.  
  121.         class CDropTarget *m_pDropTarget;   //Registered target
  122.  
  123.         //CHAPTER17MOD
  124.         UINT            m_cfEmbeddedObject; //Clipboard formats
  125.         UINT            m_cfObjectDescriptor;
  126.         //End CHAPTER17MOD
  127.  
  128.     protected:
  129.         virtual BOOL    FMessageHook(HWND, UINT, WPARAM, LPARAM
  130.             , LRESULT *);
  131.  
  132.         BOOL            FQueryPasteFromData(LPDATAOBJECT
  133.                             , LPFORMATETC, PTENANTTYPE);
  134.         //CHAPTER17MOD
  135.         BOOL            PasteFromData(LPDATAOBJECT, LPFORMATETC
  136.                             , TENANTTYPE, PPATRONOBJECT, DWORD
  137.                             , BOOL);
  138.         //End CHAPTER17MOD
  139.  
  140.     public:
  141.         CPatronDoc(HINSTANCE, PCFrame, PCDocumentAdviseSink);
  142.         virtual ~CPatronDoc(void);
  143.  
  144.         virtual BOOL    Init(PDOCUMENTINIT);
  145.         virtual void    Clear(void);
  146.  
  147.         virtual BOOL    FDirtyGet(void);
  148.         virtual void    Delete(void);
  149.         virtual BOOL    FQueryPrinterSetup(void);
  150.         virtual BOOL    FQueryObjectSelected(HMENU);
  151.  
  152.         virtual UINT    Load(BOOL, LPTSTR);
  153.         virtual UINT    Save(UINT, LPTSTR);
  154.  
  155.         virtual BOOL    Print(HWND);
  156.         virtual UINT    PrinterSetup(HWND, BOOL);
  157.  
  158.         virtual BOOL    Clip(HWND, BOOL);
  159.         virtual BOOL    FQueryPaste(void);
  160.         virtual BOOL    Paste(HWND);
  161.         virtual BOOL    PasteSpecial(HWND);
  162.  
  163.         virtual UINT    NewPage(void);
  164.         virtual UINT    DeletePage(void);
  165.         virtual UINT    NextPage(void);
  166.         virtual UINT    PreviousPage(void);
  167.         virtual UINT    FirstPage(void);
  168.         virtual UINT    LastPage(void);
  169.  
  170.         //CHAPTER17MOD
  171.         virtual void    Rename(LPTSTR);
  172.         virtual BOOL    InsertObject(HWND);
  173.         virtual void    ActivateObject(LONG);
  174.         virtual BOOL    ConvertObject(HWND);
  175.         //End CHAPTER17MOD
  176.     };
  177.  
  178. typedef CPatronDoc *PCPatronDoc;
  179.  
  180. //Hook for Print Dialog to hide Setup... button
  181. UINT CALLBACK PrintDlgHook(HWND, UINT, WPARAM, LPARAM);
  182.  
  183.  
  184. //Drag-drop objects we need in the document
  185.  
  186. class CDropTarget : public IDropTarget
  187.     {
  188.     protected:
  189.         ULONG               m_cRef;
  190.         PCPatronDoc         m_pDoc;
  191.  
  192.         LPDATAOBJECT        m_pIDataObject;  //From DragEnter
  193.         BOOL                m_fPendingRepaint;
  194.         POINTL              m_ptPick;        //Pick-up offsets
  195.         POINTL              m_ptLast;        //Last drag point
  196.         SIZEL               m_szl;           //Object size
  197.         BOOL                m_fFeedback;     //Draw feedback?
  198.         FORMATETC           m_fe;            //Real dropping format
  199.  
  200.     public:
  201.         CDropTarget(PCPatronDoc);
  202.         ~CDropTarget(void);
  203.  
  204.         //IDropTarget interface members
  205.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  206.         STDMETHODIMP_(ULONG) AddRef(void);
  207.         STDMETHODIMP_(ULONG) Release(void);
  208.  
  209.         STDMETHODIMP DragEnter(LPDATAOBJECT, DWORD, POINTL,LPDWORD);
  210.         STDMETHODIMP DragOver(DWORD, POINTL, LPDWORD);
  211.         STDMETHODIMP DragLeave(void);
  212.         STDMETHODIMP Drop(LPDATAOBJECT, DWORD, POINTL, LPDWORD);
  213.     };
  214.  
  215.  
  216. typedef CDropTarget *PCDropTarget;
  217.  
  218.  
  219. class CDropSource : public IDropSource
  220.     {
  221.     protected:
  222.         ULONG               m_cRef;
  223.  
  224.     public:
  225.         CDropSource(void);
  226.         ~CDropSource(void);
  227.  
  228.         //IDropSource interface members
  229.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  230.         STDMETHODIMP_(ULONG) AddRef(void);
  231.         STDMETHODIMP_(ULONG) Release(void);
  232.  
  233.         STDMETHODIMP QueryContinueDrag(BOOL, DWORD);
  234.         STDMETHODIMP GiveFeedback(DWORD);
  235.     };
  236.  
  237. typedef CDropSource *PCDropSource;
  238.  
  239.  
  240. #endif //_PATRON_H_
  241.