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

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