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

  1. /*
  2.  * POLYLINE.H
  3.  * Cosmo Chapter 12
  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      PointScale(LPRECT, LPPOINTS, BOOL);
  89.         void      Draw(HDC, BOOL, BOOL);
  90.         void      RectConvertMappings(LPRECT, BOOL);
  91.  
  92.     public:
  93.         CPolyline(HINSTANCE);
  94.         ~CPolyline(void);
  95.  
  96.         BOOL      Init(HWND, LPRECT, DWORD, UINT
  97.             , class CPolylineAdviseSink *);
  98.  
  99.         void      New(void);
  100.         BOOL      Undo(void);
  101.  
  102.         //File functions
  103.         LONG      ReadFromStorage(LPSTORAGE);
  104.         LONG      WriteToStorage(LPSTORAGE, LONG);
  105.  
  106.         LONG      ReadFromFile(LPTSTR);
  107.         LONG      WriteToFile(LPTSTR, LONG);
  108.  
  109.         //Data transfer functions
  110.         LONG      DataSet(PPOLYLINEDATA, BOOL, BOOL);
  111.         LONG      DataGet(PPOLYLINEDATA, LONG);
  112.         LONG      DataSetMem(HGLOBAL, BOOL, BOOL, BOOL);
  113.         LONG      DataGetMem(LONG, HGLOBAL *);
  114.         HBITMAP   RenderBitmap(void);
  115.         HMETAFILE RenderMetafile(void);
  116.         HGLOBAL   RenderMetafilePict(void);
  117.  
  118.         void      RectGet(LPRECT);
  119.         void      SizeGet(LPRECT);
  120.         void      RectSet(LPRECT, BOOL);
  121.         void      SizeSet(LPRECT, BOOL);
  122.         COLORREF  ColorSet(UINT, COLORREF);
  123.         COLORREF  ColorGet(UINT);
  124.         UINT      LineStyleSet(UINT);
  125.         UINT      LineStyleGet(void);
  126.     };
  127.  
  128. typedef CPolyline *PCPolyline;
  129.  
  130.  
  131. //Error values for data transfer functions
  132. #define POLYLINE_E_NONE                    0
  133. #define POLYLINE_E_UNSUPPORTEDVERSION      -1
  134. #define POLYLINE_E_INVALIDPOINTER          -2
  135. #define POLYLINE_E_READFAILURE             -3
  136. #define POLYLINE_E_WRITEFAILURE            -4
  137.  
  138.  
  139.  
  140.  
  141. class CPolylineAdviseSink
  142.     {
  143.     private:
  144.         LPVOID      m_pv;           //Customizable structure
  145.  
  146.     public:
  147.         CPolylineAdviseSink(LPVOID);
  148.         ~CPolylineAdviseSink(void);
  149.  
  150.         void OnPointChange(void);
  151.         void OnSizeChange(void);
  152.         void OnDataChange(void);
  153.         void OnColorChange(void);
  154.         void OnLineStyleChange(void);
  155.     };
  156.  
  157. typedef CPolylineAdviseSink *PCPolylineAdviseSink;
  158.  
  159.  
  160. //Color indices for color messages
  161. #define POLYLINECOLOR_BACKGROUND    0
  162. #define POLYLINECOLOR_LINE          1
  163.  
  164.  
  165.  
  166. #endif  //_POLYLINE_H_
  167.