Click here to Skip to main content
16,008,299 members
Home / Discussions / C#
   

C#

 
GeneralRe: Am I dreaming? Pin
leppie15-Aug-02 0:06
leppie15-Aug-02 0:06 
GeneralRe: Am I dreaming? Pin
Ray Cassick16-Aug-02 4:48
Ray Cassick16-Aug-02 4:48 
Generalhelp me Pin
imran_rafique14-Aug-02 10:31
imran_rafique14-Aug-02 10:31 
GeneralRe: help me Pin
Stephane Rodriguez.14-Aug-02 21:40
Stephane Rodriguez.14-Aug-02 21:40 
Generalwhen i execute that line Pin
imran_rafique14-Aug-02 9:30
imran_rafique14-Aug-02 9:30 
GeneralRe: when i execute that line Pin
Stephane Rodriguez.14-Aug-02 9:53
Stephane Rodriguez.14-Aug-02 9:53 
GeneralRe: when i execute that line Pin
imran_rafique14-Aug-02 10:05
imran_rafique14-Aug-02 10:05 
GeneralRe: when i execute that line Pin
Stephane Rodriguez.14-Aug-02 10:43
Stephane Rodriguez.14-Aug-02 10:43 
I am afraid there is no more windows messaging API in C#. I guess you have to use interop and pass the HWND to lower-level code to send the message for you.

Here we go : (MSDN)
/**** NativeMethods.cs ***/
public class NativeMethods
{
 public NativeMethods(){}
 [StructLayout(LayoutKind.Sequential)]
 public struct CopyDataStruct
 {
 public string ID;
 public int Length;
 public string Data;
 }
 [DllImport("user32.dll", EntryPoint="FindWindow")]
 public extern static System.IntPtr FindWindow(string lpClasName,
                                    string lpWindowName);
 public const int WM_COPYDATA = 0x004a;
 [DllImport("user32.dll", EntryPoint="SendMessage")]
 public extern static int SendMessage(System.IntPtr hWnd,
                          int Msg, int wParam,
                          ref CopyDataStruct lParam);
}

/**** SendingForm.cs ***/
private void SendingForm_Load(object sender, System.EventArgs e)
{
 ReceivingForm rec = new ReceivingForm();
 rec.Show();
}

private void button1_Click(object sender, System.EventArgs e)
{
 NativeMethods.CopyDataStruct DataStruct = new NativeMethods.CopyDataStruct
();
 DataStruct.ID = "1";
 DataStruct.Data = "Sample Text";
 DataStruct.Length = DataStruct.Data.Length;
 IntPtr WHnd = NativeMethods.FindWindow(null, "ReceivingForm");
 if(!WHnd.Equals(System.IntPtr.Zero))
 {
  NativeMethods.SendMessage(WHnd, NativeMethods.WM_COPYDATA,
                            0, ref DataStruct);
 }
}

/**** ReceivingForm.cs ***/
protected override void WndProc(ref Message m)
{
 switch(m.Msg)
 {
 case(NativeMethods.WM_COPYDATA) :
  NativeMethods.CopyDataStruct ds =
(NativeMethods.CopyDataStruct)m.GetLParam(typeof
(NativeMethods.CopyDataStruct));
  string s = ds.Data;
  break;
 default :
  break;
 }
 base.WndProc(ref m);
}

GeneralRe: when i execute that line Pin
Mark Pitman15-Aug-02 7:08
Mark Pitman15-Aug-02 7:08 
Generalc# code comment web report Pin
Shaun Wilde14-Aug-02 9:06
Shaun Wilde14-Aug-02 9:06 
GeneralRe: c# code comment web report Pin
Eric Gunnerson (msft)14-Aug-02 10:19
Eric Gunnerson (msft)14-Aug-02 10:19 
GeneralRe: c# code comment web report Pin
Shaun Wilde14-Aug-02 22:08
Shaun Wilde14-Aug-02 22:08 
GeneralChanging file permissions Pin
Alex Korchemniy14-Aug-02 6:18
Alex Korchemniy14-Aug-02 6:18 
GeneralRe: Changing file permissions Pin
albean14-Aug-02 6:33
albean14-Aug-02 6:33 
GeneralUpdate Pin
Alex Korchemniy14-Aug-02 6:37
Alex Korchemniy14-Aug-02 6:37 
GeneralRe: Update Pin
albean14-Aug-02 6:49
albean14-Aug-02 6:49 
GeneralRe: Changing file permissions Pin
David Hall15-Aug-02 5:51
professionalDavid Hall15-Aug-02 5:51 
GeneralRe: Changing file permissions Pin
Alex Korchemniy15-Aug-02 9:02
Alex Korchemniy15-Aug-02 9:02 
GeneralDrawing on the Screen Pin
albean14-Aug-02 5:53
albean14-Aug-02 5:53 
GeneralRe: Drawing on the Screen Pin
Anonymous14-Aug-02 6:04
Anonymous14-Aug-02 6:04 
GeneralRe: Drawing on the Screen Pin
albean14-Aug-02 6:13
albean14-Aug-02 6:13 
GeneralRe: Drawing on the Screen Pin
Alex Korchemniy14-Aug-02 6:28
Alex Korchemniy14-Aug-02 6:28 
GeneralRe: Drawing on the Screen Pin
Alex Korchemniy14-Aug-02 6:42
Alex Korchemniy14-Aug-02 6:42 
GeneralRe: Drawing on the Screen Pin
albean14-Aug-02 7:13
albean14-Aug-02 7:13 
GeneralRe: Drawing on the Screen Pin
Li-kai Liu (Angus)15-Aug-02 3:12
Li-kai Liu (Angus)15-Aug-02 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.