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 / chap14 / cosmo / polyline.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  4.9 KB  |  171 lines

  1. /*
  2.  * POLYLINE.H
  3.  * Cosmo Chapter 14
  4.  *
  5.  * Definitions and function prototypes for the PolyLine window
  6.  * class that can be treated like its own control.
  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 _POLYLINE_H_
  17. #define _POLYLINE_H_
  18.  
  19. //Versioning.
  20. #define VERSIONMAJOR                2
  21. #define VERSIONMINOR                0
  22. #define VERSIONCURRENT              0x00020000
  23.  
  24. //Classname
  25. #define SZCLASSPOLYLINE             TEXT("polyline")
  26.  
  27. //Stream Name that holds the data
  28. #define SZSTREAM                    OLETEXT("CONTENTS")
  29.  
  30. #define HIMETRIC_PER_INCH           2540
  31. #define CPOLYLINEPOINTS             20
  32.  
  33. //Window extra bytes and offsets
  34. #define CBPOLYLINEWNDEXTRA          (sizeof(LONG))
  35. #define PLWL_STRUCTURE              0
  36.  
  37.  
  38. //Version 2.0 Polyline Structure
  39. typedef struct tagPOLYLINEDATA
  40.     {
  41.     WORD        wVerMaj;                //Major version number.
  42.     WORD        wVerMin;                //Minor version number.
  43.     WORD        cPoints;                //Number of points.
  44.     short       fReserved;              //Obsolete from v1.0
  45.     RECTS       rc;                     //Rectangle of this figure
  46.     POINTS      rgpt[CPOLYLINEPOINTS];  //Points (0-32767 grid)
  47.  
  48.     //Version 2.0 additions
  49.     COLORREF    rgbBackground;          //Background color
  50.     COLORREF    rgbLine;                //Line color
  51.     short       iLineStyle;             //Line style
  52.     } POLYLINEDATA, *PPOLYLINEDATA;
  53.  
  54. #define CBPOLYLINEDATA   sizeof(POLYLINEDATA)
  55. #define CBPOLYLINEDATA20 sizeof(POLYLINEDATA)
  56.  
  57.  
  58. //Version 1.0 Polyline Structure
  59. typedef struct tagPOLYLINEDATA10
  60.     {
  61.     WORD        wVerMaj;                //Major version number.
  62.     WORD        wVerMin;                //Minor version number.
  63.     WORD        cPoints;                //Number of points.
  64.     short       fDrawEntire;            //Flag to draw entire figure
  65.     RECTS       rc;                     //Rectangle of this figure
  66.     POINTS      rgpt[CPOLYLINEPOINTS];  //Points (scaled to rc)
  67.     } POLYLINEDATA10, *PPOLYLINEDATA10;
  68.  
  69. #define CBPOLYLINEDATA10 sizeof(POLYLINEDATA10)
  70.  
  71.  
  72. //POLYWIN.CPP
  73. LRESULT APIENTRY PolylineWndProc(HWND, UINT, WPARAM, LPARAM);
  74.  
  75.  
  76. class CPolyline : public CWindow
  77.     {
  78.     friend LRESULT APIENTRY PolylineWndProc(HWND, UINT, WPARAM
  79.         , LPARAM);
  80.  
  81.     private:
  82.         POLYLINEDATA   m_pl;
  83.  
  84.         class CPolylineAdviseSink * m_pAdv;
  85.  
  86.     private:
  87.         HFILE     OpenFileW(LPTSTR, LPOFSTRUCT, UINT);
  88.         void      Draw(HDC, BOOL, BOOL);
  89.         void      RectConvertMappings(LPRECT, BOOL);
  90.  
  91.     public:
  92.         CPolyline(HINSTANCE);
  93.         ~CPolyline(void);
  94.  
  95.         BOOL      Init(HWND, LPRECT, DWORD, UINT
  96.             , class CPolylineAdviseSink *);
  97.  
  98.         //CHAPTER14MOD
  99.         //Needed to be public for OLE Automation
  100.         void      PointScale(LPRECT, LPPOINTS, BOOL);
  101.         //End CHAPTER14MOD
  102.  
  103.         void      New(void);
  104.         BOOL      Undo(void);
  105.  
  106.         //File functions
  107.         LONG      ReadFromStorage(LPSTORAGE);
  108.         LONG      WriteToStorage(LPSTORAGE, LONG);
  109.  
  110.         LONG      ReadFromFile(LPTSTR);
  111.         LONG      WriteToFile(LPTSTR, LONG);
  112.  
  113.         //Data transfer functions
  114.         LONG      DataSet(PPOLYLINEDATA, BOOL, BOOL);
  115.         LONG      DataGet(PPOLYLINEDATA, LONG);
  116.         LONG      DataSetMem(HGLOBAL, BOOL, BOOL, BOOL);
  117.         LONG      DataGetMem(LONG, HGLOBAL *);
  118.         HBITMAP   RenderBitmap(void);
  119.         HMETAFILE RenderMetafile(void);
  120.         HGLOBAL   RenderMetafilePict(void);
  121.  
  122.         void      RectGet(LPRECT);
  123.         void      SizeGet(LPRECT);
  124.         void      RectSet(LPRECT, BOOL);
  125.         void      SizeSet(LPRECT, BOOL);
  126.         COLORREF  ColorSet(UINT, COLORREF);
  127.         COLORREF  ColorGet(UINT);
  128.         UINT      LineStyleSet(UINT);
  129.         UINT      LineStyleGet(void);
  130.     };
  131.  
  132. typedef CPolyline *PCPolyline;
  133.  
  134.  
  135. //Error values for data transfer functions
  136. #define POLYLINE_E_NONE                    0
  137. #define POLYLINE_E_UNSUPPORTEDVERSION      -1
  138. #define POLYLINE_E_INVALIDPOINTER          -2
  139. #define POLYLINE_E_READFAILURE             -3
  140. #define POLYLINE_E_WRITEFAILURE            -4
  141.  
  142.  
  143.  
  144.  
  145. class CPolylineAdviseSink
  146.     {
  147.     private:
  148.         LPVOID      m_pv;           //Customizable structure
  149.  
  150.     public:
  151.         CPolylineAdviseSink(LPVOID);
  152.         ~CPolylineAdviseSink(void);
  153.  
  154.         void OnPointChange(void);
  155.         void OnSizeChange(void);
  156.         void OnDataChange(void);
  157.         void OnColorChange(void);
  158.         void OnLineStyleChange(void);
  159.     };
  160.  
  161. typedef CPolylineAdviseSink *PCPolylineAdviseSink;
  162.  
  163.  
  164. //Color indices for color messages
  165. #define POLYLINECOLOR_BACKGROUND    0
  166. #define POLYLINECOLOR_LINE          1
  167.  
  168.  
  169.  
  170. #endif  //_POLYLINE_H_
  171.