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 / chap15 / square / square.h < prev    next >
C/C++ Source or Header  |  1995-05-03  |  5KB  |  158 lines

  1. /*
  2.  * SQUARE.H
  3.  * Square Automation Object Chapter 15
  4.  *
  5.  * Definitions, classes, and prototypes for an EXE that
  6.  * provides Square objects to automation controllers
  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 _SQUARE_H_
  17. #define _SQUARE_H_
  18.  
  19. //Get the object definitions
  20. #define INC_AUTOMATION
  21. #define CHAPTER15
  22. #define GUIDS_FROM_TYPELIB
  23. #include <inole.h>
  24. #include <math.h>
  25.  
  26. #include "isquare.h"
  27.  
  28. LRESULT APIENTRY MainWndProc(HWND, UINT, WPARAM, LPARAM);
  29.  
  30. class CApp
  31.     {
  32.     friend LRESULT APIENTRY MainWndProc(HWND, UINT, WPARAM, LPARAM);
  33.  
  34.     protected:
  35.         HINSTANCE       m_hInst;            //WinMain parameters
  36.         HINSTANCE       m_hInstPrev;
  37.         LPSTR           m_pszCmdLine;
  38.         UINT            m_nCmdShow;
  39.  
  40.         BOOL            m_fInitialized;     //Did CoInitialize work?
  41.         LPCLASSFACTORY  m_pIClassFactory;   //Our class factory
  42.         DWORD           m_dwRegCO;          //Registration key
  43.  
  44.     public:
  45.         CApp(HINSTANCE, HINSTANCE, LPSTR, UINT);
  46.         ~CApp(void);
  47.         BOOL Init(void);
  48.     };
  49.  
  50. typedef CApp *PCApp;
  51.  
  52.  
  53. void ObjectDestroyed(void);
  54.  
  55.  
  56. class CSquareClassFactory : public IClassFactory
  57.     {
  58.     protected:
  59.         ULONG           m_cRef;
  60.         HWND            m_hWnd;         //Main window (hidden)
  61.         HINSTANCE       m_hInst;        //Module instance
  62.  
  63.     public:
  64.         CSquareClassFactory(HWND, HINSTANCE);
  65.         ~CSquareClassFactory(void);
  66.  
  67.         //IUnknown members
  68.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  69.         STDMETHODIMP_(ULONG) AddRef(void);
  70.         STDMETHODIMP_(ULONG) Release(void);
  71.  
  72.         //IClassFactory members
  73.         STDMETHODIMP  CreateInstance(LPUNKNOWN, REFIID, PPVOID);
  74.         STDMETHODIMP  LockServer(BOOL);
  75.     };
  76.  
  77. typedef CSquareClassFactory *PCSquareClassFactory;
  78.  
  79.  
  80. //Information for the window in which we draw
  81. LRESULT APIENTRY SquareWndProc(HWND, UINT, WPARAM, LPARAM);
  82.  
  83. #define SZCLASSSQUARE       TEXT("SquareWindow")
  84.  
  85.  
  86. class CSquare : public ISphereSquare
  87.     {
  88.     friend LRESULT APIENTRY SquareWndProc(HWND, UINT, WPARAM
  89.         , LPARAM);
  90.  
  91.     protected:
  92.         ULONG           m_cRef;         //Object reference count
  93.         HWND            m_hWnd;         //Drawing window.
  94.  
  95.         ITypeInfo      *m_pITypeInfo;   //Loaded
  96.         IUnknown       *m_pIUnkDisp;    //From CreateStdDispatch
  97.  
  98.         //Plotting variables
  99.         double          m_cRadius;      //Edge length
  100.         double          m_dTheta;       //Angle
  101.         double          m_dDeclin;      //Declination
  102.  
  103.         int             m_xOrg, m_yOrg; //Origin point
  104.         int             m_cx, m_cy;     //Window size
  105.         int             m_xPos, m_yPos; //Window position
  106.  
  107.         COLORREF        m_crLinePos;    //Positive line color
  108.         HPEN            m_hPenPos;      //Positive line pen
  109.  
  110.         COLORREF        m_crLineNeg;    //Negative line color
  111.         HPEN            m_hPenNeg;      //Negative line pen
  112.  
  113.         COLORREF        m_crBack;       //Background color
  114.  
  115.     public:
  116.         CSquare(void);
  117.         ~CSquare(void);
  118.  
  119.         BOOL        Init(HWND, HINSTANCE);
  120.         void        CreatePens(BOOL, BOOL);
  121.         void        Draw(HDC);
  122.  
  123.         //IUnknown Members
  124.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  125.         STDMETHODIMP_(ULONG) AddRef(void);
  126.         STDMETHODIMP_(ULONG) Release(void);
  127.  
  128.         //ISphereSquare members
  129.         STDMETHODIMP_(double) get_Radius(void);
  130.         STDMETHODIMP_(void) put_Radius(double);
  131.         STDMETHODIMP_(double) get_Theta(void);
  132.         STDMETHODIMP_(void) put_Theta(double);
  133.         STDMETHODIMP_(double) get_Declination(void);
  134.         STDMETHODIMP_(void) put_Declination(double);
  135.         STDMETHODIMP_(long) get_BackColor(void);
  136.         STDMETHODIMP_(void) put_BackColor(long);
  137.         STDMETHODIMP_(long) get_LineColorPositive(void);
  138.         STDMETHODIMP_(void) put_LineColorPositive(long);
  139.         STDMETHODIMP_(long) get_LineColorNegative(void);
  140.         STDMETHODIMP_(void) put_LineColorNegative(long);
  141.         STDMETHODIMP_(void) Draw(void);
  142.         STDMETHODIMP_(void) SetCenterPoint(int, int);
  143.         STDMETHODIMP_(void) ShowWindow(int);
  144.         STDMETHODIMP_(void) SetWindowPosition(int, int);
  145.         STDMETHODIMP_(void) SetWindowSize(int, int);
  146.     };
  147.  
  148. typedef CSquare *PCSquare;
  149.  
  150.  
  151. #define CBSQUAREWNDEXTRA        sizeof(PCSquare)
  152. #define SQWL_STRUCTURE          0
  153.  
  154. //Handy constant
  155. #define PI 3.1415926535
  156.  
  157. #endif //_SQUARE_H_
  158.