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

  1. /*
  2.  * POLYLINE.H
  3.  * Cosmo Chapter 7
  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. //CHAPTER7MOD
  28. //Stream Name that holds the data
  29. #define SZSTREAM                    OLETEXT("CONTENTS")
  30. //End CHAPTER7MOD
  31.  
  32. #define HIMETRIC_PER_INCH           2540
  33. #define CPOLYLINEPOINTS             20
  34.  
  35. //Window extra bytes and offsets
  36. #define CBPOLYLINEWNDEXTRA          (sizeof(LONG))
  37. #define PLWL_STRUCTURE              0
  38.  
  39.  
  40. //Version 2.0 Polyline Structure
  41. typedef struct tagPOLYLINEDATA
  42.     {
  43.     WORD        wVerMaj;                //Major version number.
  44.     WORD        wVerMin;                //Minor version number.
  45.     WORD        cPoints;                //Number of points.
  46.     short       fReserved;              //Obsolete from v1.0
  47.     RECTS       rc;                     //Rectangle of this figure
  48.     POINTS      rgpt[CPOLYLINEPOINTS];  //Points (0-32767 grid)
  49.  
  50.     //Version 2.0 additions
  51.     COLORREF    rgbBackground;          //Background color
  52.     COLORREF    rgbLine;                //Line color
  53.     short       iLineStyle;             //Line style
  54.     } POLYLINEDATA, *PPOLYLINEDATA;
  55.  
  56. #define CBPOLYLINEDATA   sizeof(POLYLINEDATA)
  57. #define CBPOLYLINEDATA20 sizeof(POLYLINEDATA)
  58.  
  59.  
  60. //Version 1.0 Polyline Structure
  61. typedef struct tagPOLYLINEDATA10
  62.     {
  63.     WORD        wVerMaj;                //Major version number.
  64.     WORD        wVerMin;                //Minor version number.
  65.     WORD        cPoints;                //Number of points.
  66.     short       fDrawEntire;            //Flag to draw entire figure
  67.     RECTS       rc;                     //Rectangle of this figure
  68.     POINTS      rgpt[CPOLYLINEPOINTS];  //Points (scaled to rc)
  69.     } POLYLINEDATA10, *PPOLYLINEDATA10;
  70.  
  71. #define CBPOLYLINEDATA10 sizeof(POLYLINEDATA10)
  72.  
  73.  
  74. //POLYWIN.CPP
  75. LRESULT APIENTRY PolylineWndProc(HWND, UINT, WPARAM, LPARAM);
  76.  
  77.  
  78. class CPolyline : public CWindow
  79.     {
  80.     friend LRESULT APIENTRY PolylineWndProc(HWND, UINT, WPARAM
  81.         , LPARAM);
  82.  
  83.     private:
  84.         POLYLINEDATA   m_pl;
  85.  
  86.         class CPolylineAdviseSink * m_pAdv;
  87.  
  88.     private:
  89.         HFILE     OpenFileW(LPTSTR, LPOFSTRUCT, UINT);
  90.         void      PointScale(LPRECT, LPPOINTS, BOOL);
  91.         void      Draw(HDC, BOOL, BOOL);
  92.         void      RectConvertMappings(LPRECT, BOOL);
  93.  
  94.     public:
  95.         CPolyline(HINSTANCE);
  96.         ~CPolyline(void);
  97.  
  98.         BOOL      Init(HWND, LPRECT, DWORD, UINT
  99.             , class CPolylineAdviseSink *);
  100.  
  101.         void      New(void);
  102.         BOOL      Undo(void);
  103.  
  104.         //File functions
  105.         //CHAPTER7MOD
  106.         LONG      ReadFromStorage(LPSTORAGE);
  107.         LONG      WriteToStorage(LPSTORAGE, LONG);
  108.         //End CHAPTER7MOD
  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.