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

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