none
如何序列化CRgn对象? RRS feed

  • 问题

  • 因为程序需要,我要把CRgn对象存储到硬盘上。但是CArchive不支持这种格式对象。因此在这里求教各位大侠了!
    2012年6月19日 23:15

答案

  • 的确是一行一个rect的,这是用网格来逼近直线,在不同的计算机上可能有不同的结果。如果光是序列化rgndata的话当然可以这么做,但是如果用来还原Path的话未必精确。


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    2012年6月21日 17:19
    版主

全部回复

  • MSDN上有讲到如何序列化
    Five main steps are required to make a class serializable. They are listed below and explained in the following sections:
    1. Deriving your class from CObject (or from some class derived from CObject).

    2. Overriding the Serialize member function.

    3. Using the DECLARE_SERIAL macro in the class declaration.

    4. Defining a constructor that takes no arguments.

    5. Using the IMPLEMENT_SERIAL macro in the implementation file for your class.

    If you call Serialize directly rather than through the >> and << operators of <link keywords="9E950D23-B874-456E-AE4B-FE00781A7699" tabIndex="0" />, the last three steps are not required for serialization.


    CRgn派生自CGdiObject,CGdiObject派生自CObject类,重载Serialize函数。

    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.

    2012年6月20日 0:57
    版主
  • CRgn不支持序列化。不过你可以序列化创建了这个对象的步骤,比如如果是line to出来的结果的话,把起始点和线宽记录下来。


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    2012年6月20日 5:17
    版主
  • 这个大概可以吧:

    DWORD GetRegionData( HRGN hRgn, // handle to region
    DWORD dwCount, // size of region data buffer
    LPRGNDATA
    lpRgnData // region data buffer );

    HRGN ExtCreateRegion( CONST XFORM *lpXform, // transformation data
    DWORD nCount, // size of region data
    CONST RGNDATA *lpRgnData // region data buffer );

    2012年6月20日 5:44
  • 这个只对CreateFromRect的有用吧?CreateFromPath的呢?


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    2012年6月20日 14:04
    版主
  • 没试过但是,这是RGNDATA的定义
    typedef struct _RGNDATAHEADER {
        DWORD   dwSize;
        DWORD   iType;
        DWORD   nCount;
        DWORD   nRgnSize;
        RECT    rcBound;
    } RGNDATAHEADER, *PRGNDATAHEADER;
    
    typedef struct _RGNDATA {
        RGNDATAHEADER   rdh;
        char            Buffer[1];
    } RGNDATA, *PRGNDATA, NEAR *NPRGNDATA, FAR *LPRGNDATA;
    
    所以,RGNDATA是变长的结构,应该不仅仅支持RECT。GetRegionData函数的参数dwCount是字节,不是RGNDATA数组的大小。
    2012年6月21日 7:20
  • 那个butter[1]是Rect数组的首地址……


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    2012年6月21日 13:51
    版主
  • 我看了msdn,你说的没错,确实buffer是RECT数组。但是我试了一下,用path画了一个大约100*100大小的三角形。
    最后得到的RGNDATA由99个RECT组成,也就是一行一个RECT。

    2012年6月21日 16:33
  • 的确是一行一个rect的,这是用网格来逼近直线,在不同的计算机上可能有不同的结果。如果光是序列化rgndata的话当然可以这么做,但是如果用来还原Path的话未必精确。


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    2012年6月21日 17:19
    版主
  • 不是序列化rgn吗。要序列化path用metafile。
    2012年6月23日 4:57