/// <summary>
 /// Encode a RECT.
 /// </summary>
 private void EncodeRect(RECT rct, PduMarshaler marshaler)
 {
     marshaler.WriteInt32(rct.left);
     marshaler.WriteInt32(rct.top);
     marshaler.WriteInt32(rct.right);
     marshaler.WriteInt32(rct.bottom);
 }
        /// <summary>
        /// Create a MAPPED_GEOMETRY_PACKET
        /// </summary>
        /// <param name="mappingId">The id for the geometry mapping.</param>
        /// <param name="updateType">The update type.</param>
        /// <param name="left">The position to left bound.</param>
        /// <param name="top">The position to right bound.</param>
        /// <param name="width">The width of the rect.</param>
        /// <param name="height">The height of the rect.</param>
        /// <returns>MAPPED_GEOMETRY_PACKET created</returns>
        public MAPPED_GEOMETRY_PACKET CreateMappedGeometryPacket(UInt64 mappingId, UpdateTypeValues updateType, uint left, uint top, uint width, uint height)
        {
            MAPPED_GEOMETRY_PACKET geometry = new MAPPED_GEOMETRY_PACKET();

            if (updateType == UpdateTypeValues.GEOMETRY_UPDATE)
            {
                geometry.cbGeometryData = 0x79;
                geometry.Version = RdpegtVersionValues.RDP8;
                geometry.MappingId = mappingId;
                geometry.UpdateType = updateType;
                geometry.Flags = 0x0;
                geometry.TopLevelId = mappingId;
                geometry.Left = 0;
                geometry.Top = 0;
                geometry.Right = width;
                geometry.Bottom = height;
                geometry.TopLevelLeft = left;
                geometry.TopLevelTop = top;
                geometry.TopLevelRight = (uint)(left + width); ;
                geometry.TopLevelBottom = (uint)(top + height); ;
                geometry.GeometryType = GeometryTypeValues.RDP8;
                geometry.cbGeometryBuffer = 0x0030;
                geometry.pGeometryBuffer = new RGNDATA();
                geometry.pGeometryBuffer.rdh.dwSize = 32;
                geometry.pGeometryBuffer.rdh.iType = 0x0001;
                geometry.pGeometryBuffer.rdh.nCount = 0x0001;
                geometry.pGeometryBuffer.rdh.nRgnSize = 0;
                geometry.pGeometryBuffer.rdh.rcBound.left = (int)left;
                geometry.pGeometryBuffer.rdh.rcBound.top = (int)top;
                geometry.pGeometryBuffer.rdh.rcBound.right = (int)(left + width);
                geometry.pGeometryBuffer.rdh.rcBound.bottom = (int)(top + height);
                geometry.pGeometryBuffer.Buffer = new RECT[1];
                RECT rct = new RECT();
                rct.left = 0;
                rct.top = 0;
                rct.right = (int)width;
                rct.bottom = (int)height;
                geometry.pGeometryBuffer.Buffer[0] = rct;
                geometry.Reserved2 = 0;
            }
            else if (updateType == UpdateTypeValues.GEOMETRY_CLEAR)
            {
                geometry.cbGeometryData = 0x0049;
                geometry.Version = RdpegtVersionValues.RDP8;
                geometry.MappingId = mappingId;
                geometry.UpdateType = updateType;
                geometry.cbGeometryBuffer = 0;
                geometry.Reserved2 = 0;
            }

            return geometry;
        }
 /// <summary>
 /// Decode to a RECT.
 /// </summary>
 private void DecodeRect(PduMarshaler marshaler, out RECT rct)
 {
     rct = new RECT();
     rct.left = marshaler.ReadInt32();
     rct.top = marshaler.ReadInt32();
     rct.right = marshaler.ReadInt32();
     rct.bottom = marshaler.ReadInt32();
 }