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

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