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 / chap20 / patron / patron.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  6.9 KB  |  248 lines

  1. /*
  2.  * PATRON.H
  3.  * Patron Chapter 20
  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. //CHAPTER20MOD
  22. #define CHAPTER20
  23. //End CHAPTER20MOD
  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.         virtual BOOL        FMessageHook(HWND, UINT, WPARAM, LPARAM
  51.                                 , LRESULT *);
  52.         virtual BOOL        RegisterAllClasses(void);
  53.         virtual UINT        CreateToolbar(void);
  54.         virtual LRESULT     OnCommand(HWND, WPARAM, LPARAM);
  55.  
  56.     public:
  57.         CPatronFrame(HINSTANCE, HINSTANCE, LPSTR, int);
  58.         virtual ~CPatronFrame(void);
  59.  
  60.         //Overrides
  61.         virtual BOOL        Init(PFRAMEINIT);
  62.  
  63.         virtual void        UpdateMenus(HMENU, UINT);
  64.         virtual void        UpdateToolbar(void);
  65.  
  66.     };
  67.  
  68.  
  69. typedef CPatronFrame *PCPatronFrame;
  70.  
  71.  
  72.  
  73.  
  74.  
  75. //CLIENT.CPP
  76.  
  77. /*
  78.  * The only reason we have a derived class here is to override
  79.  * CreateCDocument so we can create our own type as well as
  80.  * overriding NewDocument to perform one other piece of work once
  81.  * the document's been created.
  82.  */
  83.  
  84. class CPatronClient : public CClient
  85.     {
  86.     protected:
  87.         //Overridable for creating a new CDocument
  88.         virtual PCDocument CreateCDocument(void);
  89.  
  90.     public:
  91.         CPatronClient(HINSTANCE, PCFrame);
  92.         virtual ~CPatronClient(void);
  93.     };
  94.  
  95.  
  96. typedef CPatronClient *PCPatronClient;
  97.  
  98.  
  99.  
  100.  
  101. //DOCUMENT.CPP
  102.  
  103. //Constant ID for the pages window that lives in a document window
  104. #define ID_PAGES            723
  105.  
  106.  
  107. class CPatronDoc : public CDocument
  108.     {
  109.     //These need access to FQueryPasteFromData, PasteFromData
  110.     friend class CDropTarget;
  111.     friend class CDropSource;
  112.  
  113.     protected:
  114.         LONG            m_lVer;         //Loaded data version
  115.         PCPages         m_pPG;          //Pages window in us
  116.         LPSTORAGE       m_pIStorage;    //Root storage for document
  117.         BOOL            m_fPrintSetup;
  118.  
  119.         class CDropTarget *m_pDropTarget;   //Registered target
  120.  
  121.         UINT            m_cfEmbeddedObject; //Clipboard formats
  122.         UINT            m_cfObjectDescriptor;
  123.         //CHAPTER20MOD
  124.         UINT            m_cfLinkSource;
  125.         UINT            m_cfLinkSrcDescriptor;
  126.         BOOL            m_fShowTypes;       //Show Objects active?
  127.         //End CHAPTER20MOD
  128.  
  129.     protected:
  130.         virtual BOOL    FMessageHook(HWND, UINT, WPARAM, LPARAM
  131.             , LRESULT *);
  132.  
  133.         BOOL            FQueryPasteFromData(LPDATAOBJECT
  134.                             , LPFORMATETC, PTENANTTYPE);
  135.         //CHAPTER20MOD
  136.         BOOL            FQueryPasteLinkFromData(LPDATAOBJECT
  137.                             , LPFORMATETC, PTENANTTYPE);
  138.         //End CHAPTER20MOD
  139.         BOOL            PasteFromData(LPDATAOBJECT, LPFORMATETC
  140.                             , TENANTTYPE, PPATRONOBJECT, DWORD
  141.                             , BOOL);
  142.  
  143.     public:
  144.         CPatronDoc(HINSTANCE, PCFrame, PCDocumentAdviseSink);
  145.         virtual ~CPatronDoc(void);
  146.  
  147.         virtual BOOL    Init(PDOCUMENTINIT);
  148.         virtual void    Clear(void);
  149.  
  150.         virtual BOOL    FDirtyGet(void);
  151.         virtual void    Delete(void);
  152.         virtual BOOL    FQueryPrinterSetup(void);
  153.         virtual BOOL    FQueryObjectSelected(HMENU);
  154.  
  155.         virtual UINT    Load(BOOL, LPTSTR);
  156.         virtual UINT    Save(UINT, LPTSTR);
  157.  
  158.         virtual BOOL    Print(HWND);
  159.         virtual UINT    PrinterSetup(HWND, BOOL);
  160.  
  161.         virtual BOOL    Clip(HWND, BOOL);
  162.         virtual BOOL    FQueryPaste(void);
  163.         virtual BOOL    Paste(HWND);
  164.         virtual BOOL    PasteSpecial(HWND);
  165.  
  166.         //CHAPTER20MOD
  167.         virtual BOOL    FQueryEnableEditLinks(void);
  168.         virtual BOOL    EditLinks(HWND);
  169.         virtual BOOL    ShowOrQueryObjectTypes(BOOL, BOOL);
  170.         //End CHAPTER20MOD
  171.  
  172.         virtual UINT    NewPage(void);
  173.         virtual UINT    DeletePage(void);
  174.         virtual UINT    NextPage(void);
  175.         virtual UINT    PreviousPage(void);
  176.         virtual UINT    FirstPage(void);
  177.         virtual UINT    LastPage(void);
  178.  
  179.         virtual void    Rename(LPTSTR);
  180.         virtual BOOL    InsertObject(HWND);
  181.         virtual void    ActivateObject(LONG);
  182.         virtual BOOL    ConvertObject(HWND);
  183.     };
  184.  
  185. typedef CPatronDoc *PCPatronDoc;
  186.  
  187. //Hook for Print Dialog to hide Setup... button
  188. UINT CALLBACK PrintDlgHook(HWND, UINT, WPARAM, LPARAM);
  189.  
  190.  
  191. //Drag-drop objects we need in the document
  192.  
  193. class CDropTarget : public IDropTarget
  194.     {
  195.     protected:
  196.         ULONG               m_cRef;
  197.         PCPatronDoc         m_pDoc;
  198.  
  199.         LPDATAOBJECT        m_pIDataObject;  //From DragEnter
  200.         BOOL                m_fPendingRepaint;
  201.         POINTL              m_ptPick;        //Pick-up offsets
  202.         POINTL              m_ptLast;        //Last drag point
  203.         SIZEL               m_szl;           //Object size
  204.         BOOL                m_fFeedback;     //Draw feedback?
  205.         FORMATETC           m_fe;            //Real dropping format
  206.  
  207.     public:
  208.         CDropTarget(PCPatronDoc);
  209.         ~CDropTarget(void);
  210.  
  211.         //IDropTarget interface members
  212.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  213.         STDMETHODIMP_(ULONG) AddRef(void);
  214.         STDMETHODIMP_(ULONG) Release(void);
  215.  
  216.         STDMETHODIMP DragEnter(LPDATAOBJECT, DWORD, POINTL,LPDWORD);
  217.         STDMETHODIMP DragOver(DWORD, POINTL, LPDWORD);
  218.         STDMETHODIMP DragLeave(void);
  219.         STDMETHODIMP Drop(LPDATAOBJECT, DWORD, POINTL, LPDWORD);
  220.     };
  221.  
  222.  
  223. typedef CDropTarget *PCDropTarget;
  224.  
  225.  
  226. class CDropSource : public IDropSource
  227.     {
  228.     protected:
  229.         ULONG               m_cRef;
  230.  
  231.     public:
  232.         CDropSource(void);
  233.         ~CDropSource(void);
  234.  
  235.         //IDropSource interface members
  236.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  237.         STDMETHODIMP_(ULONG) AddRef(void);
  238.         STDMETHODIMP_(ULONG) Release(void);
  239.  
  240.         STDMETHODIMP QueryContinueDrag(BOOL, DWORD);
  241.         STDMETHODIMP GiveFeedback(DWORD);
  242.     };
  243.  
  244. typedef CDropSource *PCDropSource;
  245.  
  246.  
  247. #endif //_PATRON_H_
  248.