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

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