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 / cosmo / cosmo.h < prev    next >
C/C++ Source or Header  |  1995-05-03  |  6KB  |  230 lines

  1. /*
  2.  * COSMO.H
  3.  * Cosmo Chapter 13
  4.  *
  5.  * Single include file that pulls in everything needed for other
  6.  * source files in the Cosmo 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 _COSMO_H_
  17. #define _COSMO_H_
  18.  
  19. #define INC_CLASSLIB
  20. //CHAPTER13MOD
  21. #define CHAPTER13
  22. //End CHAPTER13MOD
  23. #include <inole.h>
  24. #include "resource.h"
  25.  
  26. //Get the editor window information.
  27. #include "polyline.h"
  28.  
  29.  
  30.  
  31. //COSMO.CPP:  Frame object that creates a main window
  32.  
  33. class CCosmoFrame : public CFrame
  34.     {
  35.     private:
  36.         HBITMAP         m_hBmpLines[5];     //Menu item bitmaps
  37.         UINT            m_uIDCurLine;       //Current line selection
  38.         BOOL            m_fInitialized;     //Did OleInitalize work?
  39.         LPCLASSFACTORY  m_pIClassDataTran;  //For locking
  40.  
  41.     protected:
  42.         //Overridable for creating a CClient for this frame
  43.         virtual PCClient  CreateCClient(void);
  44.  
  45.         virtual BOOL      RegisterAllClasses(void);
  46.         virtual BOOL      PreShowInit(void);
  47.         virtual UINT      CreateToolbar(void);
  48.  
  49.         virtual LRESULT   OnCommand(HWND, WPARAM, LPARAM);
  50.         virtual void      OnDocumentDataChange(PCDocument);
  51.         virtual void      OnDocumentActivate(PCDocument);
  52.  
  53.         //New for this class
  54.         virtual void      CreateLineMenu(void);
  55.  
  56.     public:
  57.         CCosmoFrame(HINSTANCE, HINSTANCE, LPSTR, int);
  58.         virtual ~CCosmoFrame(void);
  59.  
  60.         //Overrides
  61.         virtual BOOL      Init(PFRAMEINIT);
  62.         virtual void      UpdateMenus(HMENU, UINT);
  63.         virtual void      UpdateToolbar(void);
  64.  
  65.         //New for this class
  66.         virtual void      CheckLineSelection(UINT);
  67.     };
  68.  
  69.  
  70. typedef CCosmoFrame *PCCosmoFrame;
  71.  
  72.  
  73.  
  74.  
  75.  
  76. //CLIENT.CPP
  77.  
  78. /*
  79.  * The only reason we have a derived class here is to override
  80.  * CreateCDocument so we can create our own type as well as
  81.  * overriding NewDocument to perform one other piece of work once
  82.  * the document's been created.
  83.  */
  84.  
  85. class CCosmoClient : public CClient
  86.     {
  87.     protected:
  88.         //Overridable for creating a new CDocument
  89.         virtual PCDocument CreateCDocument(void);
  90.  
  91.     public:
  92.         CCosmoClient(HINSTANCE, PCFrame);
  93.         virtual ~CCosmoClient(void);
  94.  
  95.         virtual PCDocument NewDocument(BOOL);
  96.     };
  97.  
  98.  
  99. typedef CCosmoClient *PCCosmoClient;
  100.  
  101.  
  102.  
  103.  
  104. //DOCUMENT.CPP
  105.  
  106. //Constant ID for the window polyline that lives in a document
  107. #define ID_POLYLINE         10
  108.  
  109.  
  110. class CCosmoDoc : public CDocument
  111.     {
  112.     friend class CPolylineAdviseSink;
  113.  
  114.     //CHAPTER13MOD
  115.     //These need access to FQueryPasteFromData, PasteFromData
  116.     friend class CDropTarget;
  117.     friend class CDropSource;
  118.     //End CHAPTER13MOD
  119.  
  120.     protected:
  121.         UINT                    m_uPrevSize;    //Last WM_SIZE wParam
  122.         LONG                    m_lVer;         //Loaded Polyline ver
  123.  
  124.         PCPolyline              m_pPL;          //Polyline window here
  125.         PCPolylineAdviseSink    m_pPLAdv;       //Advises from Polyline
  126.  
  127.         //CHAPTER13MOD
  128.         class CDropTarget      *m_pDropTarget;  //Registered target
  129.         BOOL                    m_fDragSource;  //Source==target?
  130.         //End CHAPTER13MOD
  131.  
  132.     protected:
  133.         virtual BOOL     FMessageHook(HWND, UINT, WPARAM, LPARAM
  134.             , LRESULT *);
  135.  
  136.         virtual BOOL     FQueryPasteFromData(LPDATAOBJECT);
  137.         virtual BOOL     PasteFromData(LPDATAOBJECT);
  138.  
  139.         //CHAPTER13MOD
  140.         LPDATAOBJECT     TransferObjectCreate(BOOL);
  141.         void             DropSelectTargetWindow(void);
  142.         //End CHAPTER13MOD
  143.  
  144.     public:
  145.         CCosmoDoc(HINSTANCE, PCFrame, PCDocumentAdviseSink);
  146.         virtual ~CCosmoDoc(void);
  147.  
  148.         virtual BOOL     Init(PDOCUMENTINIT);
  149.  
  150.         virtual void     Clear(void);
  151.  
  152.         virtual UINT     Load(BOOL, LPTSTR);
  153.         virtual UINT     Save(UINT, LPTSTR);
  154.  
  155.         virtual void     Undo(void);
  156.         virtual BOOL     Clip(HWND, BOOL);
  157.         virtual HGLOBAL  RenderFormat(UINT);
  158.         virtual BOOL     FQueryPaste(void);
  159.         virtual BOOL     Paste(HWND);
  160.  
  161.         virtual COLORREF ColorSet(UINT, COLORREF);
  162.         virtual COLORREF ColorGet(UINT);
  163.  
  164.         virtual UINT     LineStyleSet(UINT);
  165.         virtual UINT     LineStyleGet(void);
  166.     };
  167.  
  168. typedef CCosmoDoc *PCCosmoDoc;
  169.  
  170.  
  171. //These color indices wrap the polyline definitions
  172. #define DOCCOLOR_BACKGROUND             POLYLINECOLOR_BACKGROUND
  173. #define DOCCOLOR_LINE                   POLYLINECOLOR_LINE
  174.  
  175.  
  176. //CHAPTER13MOD
  177. //Drag-drop interfaces we need in the document
  178. class CDropTarget : public IDropTarget
  179.     {
  180.     protected:
  181.         ULONG               m_cRef;
  182.         PCCosmoDoc          m_pDoc;
  183.  
  184.         LPDATAOBJECT        m_pIDataObject;     //From DragEnter
  185.  
  186.     public:
  187.         CDropTarget(PCCosmoDoc);
  188.         ~CDropTarget(void);
  189.  
  190.         //IDropTarget interface members
  191.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  192.         STDMETHODIMP_(ULONG) AddRef(void);
  193.         STDMETHODIMP_(ULONG) Release(void);
  194.  
  195.         STDMETHODIMP DragEnter(LPDATAOBJECT, DWORD, POINTL, LPDWORD);
  196.         STDMETHODIMP DragOver(DWORD, POINTL, LPDWORD);
  197.         STDMETHODIMP DragLeave(void);
  198.         STDMETHODIMP Drop(LPDATAOBJECT, DWORD, POINTL, LPDWORD);
  199.     };
  200.  
  201.  
  202. typedef CDropTarget *PCDropTarget;
  203.  
  204.  
  205. class CDropSource : public IDropSource
  206.     {
  207.     protected:
  208.         ULONG               m_cRef;
  209.         PCCosmoDoc          m_pDoc;
  210.  
  211.     public:
  212.         CDropSource(PCCosmoDoc);
  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.  
  225. typedef CDropSource *PCDropSource;
  226.  
  227. //End CHAPTER13MOD
  228.  
  229. #endif //_COSMO_H_
  230.