Exemplo n.º 1
0
		/// <summary>
		/// Override for a form's Window Procedure to handle WM_COPYDATA
		/// messages sent by other instances of this class.
		/// </summary>
		/// <param name="m">The Windows Message information.</param>
		protected override void WndProc (ref System.Windows.Forms.Message m )
		{
			if (m.Msg == WM_COPYDATA)
			{
				COPYDATASTRUCT cds = new COPYDATASTRUCT();
				cds = (COPYDATASTRUCT) Marshal.PtrToStructure(m.LParam, typeof(COPYDATASTRUCT));
				if (cds.cbData > 0)
				{
					byte[] data = new byte[cds.cbData];				
					Marshal.Copy(cds.lpData, data, 0, cds.cbData);
					MemoryStream stream = new MemoryStream(data);
					BinaryFormatter b = new BinaryFormatter();
					CopyDataObjectData cdo = (CopyDataObjectData) b.Deserialize(stream);
					
					if (channels.Contains(cdo.Channel))
					{
						DataReceivedEventArgs d = new DataReceivedEventArgs(cdo.Channel, cdo.Data, cdo.Sent);
						OnDataReceived(d);
						m.Result = (IntPtr) 1;
					}				
				}
			}
			else if (m.Msg == WM_DESTROY)
			{
				// WM_DESTROY fires before OnHandleChanged and is
				// a better place to ensure that we've cleared 
				// everything up.
				channels.OnHandleChange();
				base.OnHandleChange();
			}
			base.WndProc(ref m);
		}
Exemplo n.º 2
0
		/// <summary>
		/// Raises the DataReceived event from this class.
		/// </summary>
		/// <param name="e">The data which has been received.</param>
		protected void OnDataReceived(DataReceivedEventArgs e)
		{
			DataReceived(this, e);
		}