POLYLINE.H
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:5k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /*
  2.  * POLYLINE.H
  3.  * Cosmo Chapter 13
  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. #ifndef _POLYLINE_H_
  15. #define _POLYLINE_H_
  16. //Versioning.
  17. #define VERSIONMAJOR                2
  18. #define VERSIONMINOR                0
  19. #define VERSIONCURRENT              0x00020000
  20. //Classname
  21. #define SZCLASSPOLYLINE             TEXT("polyline")
  22. //Stream Name that holds the data
  23. #define SZSTREAM                    OLETEXT("CONTENTS")
  24. #define HIMETRIC_PER_INCH           2540
  25. #define CPOLYLINEPOINTS             20
  26. //Window extra bytes and offsets
  27. #define CBPOLYLINEWNDEXTRA          (sizeof(LONG))
  28. #define PLWL_STRUCTURE              0
  29. //Version 2.0 Polyline Structure
  30. typedef struct tagPOLYLINEDATA
  31.     {
  32.     WORD        wVerMaj;                //Major version number.
  33.     WORD        wVerMin;                //Minor version number.
  34.     WORD        cPoints;                //Number of points.
  35.     short       fReserved;              //Obsolete from v1.0
  36.     RECTS       rc;                     //Rectangle of this figure
  37.     POINTS      rgpt[CPOLYLINEPOINTS];  //Points (0-32767 grid)
  38.     //Version 2.0 additions
  39.     COLORREF    rgbBackground;          //Background color
  40.     COLORREF    rgbLine;                //Line color
  41.     short       iLineStyle;             //Line style
  42.     } POLYLINEDATA, *PPOLYLINEDATA;
  43. #define CBPOLYLINEDATA   sizeof(POLYLINEDATA)
  44. #define CBPOLYLINEDATA20 sizeof(POLYLINEDATA)
  45. //Version 1.0 Polyline Structure
  46. typedef struct tagPOLYLINEDATA10
  47.     {
  48.     WORD        wVerMaj;                //Major version number.
  49.     WORD        wVerMin;                //Minor version number.
  50.     WORD        cPoints;                //Number of points.
  51.     short       fDrawEntire;            //Flag to draw entire figure
  52.     RECTS       rc;                     //Rectangle of this figure
  53.     POINTS      rgpt[CPOLYLINEPOINTS];  //Points (scaled to rc)
  54.     } POLYLINEDATA10, *PPOLYLINEDATA10;
  55. #define CBPOLYLINEDATA10 sizeof(POLYLINEDATA10)
  56. //POLYWIN.CPP
  57. LRESULT APIENTRY PolylineWndProc(HWND, UINT, WPARAM, LPARAM);
  58. class CPolyline : public CWindow
  59.     {
  60.     friend LRESULT APIENTRY PolylineWndProc(HWND, UINT, WPARAM
  61.         , LPARAM);
  62.     private:
  63.         POLYLINEDATA   m_pl;
  64.         class CPolylineAdviseSink * m_pAdv;
  65.     private:
  66.         HFILE     OpenFileW(LPTSTR, LPOFSTRUCT, UINT);
  67.         void      PointScale(LPRECT, LPPOINTS, BOOL);
  68.         void      Draw(HDC, BOOL, BOOL);
  69.         void      RectConvertMappings(LPRECT, BOOL);
  70.     public:
  71.         CPolyline(HINSTANCE);
  72.         ~CPolyline(void);
  73.         BOOL      Init(HWND, LPRECT, DWORD, UINT
  74.             , class CPolylineAdviseSink *);
  75.         void      New(void);
  76.         BOOL      Undo(void);
  77.         //File functions
  78.         LONG      ReadFromStorage(LPSTORAGE);
  79.         LONG      WriteToStorage(LPSTORAGE, LONG);
  80.         LONG      ReadFromFile(LPTSTR);
  81.         LONG      WriteToFile(LPTSTR, LONG);
  82.         //Data transfer functions
  83.         LONG      DataSet(PPOLYLINEDATA, BOOL, BOOL);
  84.         LONG      DataGet(PPOLYLINEDATA, LONG);
  85.         LONG      DataSetMem(HGLOBAL, BOOL, BOOL, BOOL);
  86.         LONG      DataGetMem(LONG, HGLOBAL *);
  87.         HBITMAP   RenderBitmap(void);
  88.         HMETAFILE RenderMetafile(void);
  89.         HGLOBAL   RenderMetafilePict(void);
  90.         void      RectGet(LPRECT);
  91.         void      SizeGet(LPRECT);
  92.         void      RectSet(LPRECT, BOOL);
  93.         void      SizeSet(LPRECT, BOOL);
  94.         COLORREF  ColorSet(UINT, COLORREF);
  95.         COLORREF  ColorGet(UINT);
  96.         UINT      LineStyleSet(UINT);
  97.         UINT      LineStyleGet(void);
  98.     };
  99. typedef CPolyline *PCPolyline;
  100. //Error values for data transfer functions
  101. #define POLYLINE_E_NONE                    0
  102. #define POLYLINE_E_UNSUPPORTEDVERSION      -1
  103. #define POLYLINE_E_INVALIDPOINTER          -2
  104. #define POLYLINE_E_READFAILURE             -3
  105. #define POLYLINE_E_WRITEFAILURE            -4
  106. class CPolylineAdviseSink
  107.     {
  108.     private:
  109.         LPVOID      m_pv;           //Customizable structure
  110.     public:
  111.         CPolylineAdviseSink(LPVOID);
  112.         ~CPolylineAdviseSink(void);
  113.         void OnPointChange(void);
  114.         void OnSizeChange(void);
  115.         void OnDataChange(void);
  116.         void OnColorChange(void);
  117.         void OnLineStyleChange(void);
  118.     };
  119. typedef CPolylineAdviseSink *PCPolylineAdviseSink;
  120. //Color indices for color messages
  121. #define POLYLINECOLOR_BACKGROUND    0
  122. #define POLYLINECOLOR_LINE          1
  123. #endif  //_POLYLINE_H_