How to read a windows message posted by another application

G

Guest

Hi,
I want to post a windows message from one application and read it in another
application.

I am using the below code to post a message to a form but i am not able to
read the message in the receiving form in another application.

IntPtr hWnd;
hWnd = FindWindow(null, "MsgWindow");
int i = PostMessage(hWnd, 5000, 5000, 5000);
if (i == 0)
MessageBox.Show("Window not found!");

[DllImport("coredll.dll")]
public extern static int SendMessage(IntPtr hwnd, uint msg, uint wParam,
uint lParam);
[DllImport("coredll.dll")]
public extern static int PostMessage(IntPtr hwnd, uint msg, uint wParam,
uint lParam);
[DllImport("coredll.dll", EntryPoint = "FindWindowW", CharSet =
CharSet.Unicode)]
public static extern IntPtr FindWindow(String strClass, String strWindowName);

Can some one tell me how that can be done and any sample code showing how it
can be done.

Thanks,
Murthy
 
F

Fabien

Hi,

you can override the WndProc procedure and catch the message you
want :

protected override void WndProc(ref Message msg)
{
switch(msg.Msg)
{
case YOUR_MSG:
break;


}

// call the base class WndProc for default message handling
base.WndProc(ref msg);
}


}


BR


Fabien Decret
Windows Embedded Consultant

ADENEO (ADESET)
http://www.adeneo.adetelgroup.com/



Murthy a écrit :
 
G

Guest

Where's the receiving end code? Having just a send is like having a phone
call with one phone - not too useful.
 
G

Guest

Hi,
I tried the following code in the receiving form.
But it is not receiving any message.
i have put a break point in wndproc but the control is not coming there.
In form load i created an instance of myMessageWindowClass....
But this is not working what is it that i am missing...

public class myMessageWindowClass : MessageWindow
{
// Assign integers to messages.
// Note that custom Window messages are after WM_USER = 0x400.
public const int WM_BOXUPDATE = 0x0401;
public const int WM_PNLUPDATE = 0x0402;


// Create an instance of the form.
MsgWindow updateform;

// Save reference to the form so it can
// be notified when messages are received.
public myMessageWindowClass(MsgWindow updateform)
{
this.updateform = updateform;
}

// Override the default WndProc behavior to examine messages.
protected override void WndProc(ref Message msg)
{
switch (msg.Msg)
{
}

// Call the base class WndProc for default message handling.
base.WndProc(ref msg);
}
}

Can someone give me a sample code that will receive any message posted to it
from another application.

Thanks in Advance,
Murthy


Where's the receiving end code? Having just a send is like having a phone
call with one phone - not too useful.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Murthy said:
Hi,
I want to post a windows message from one application and read it in
another
application.

I am using the below code to post a message to a form but i am not able to
read the message in the receiving form in another application.

IntPtr hWnd;
hWnd = FindWindow(null, "MsgWindow");
int i = PostMessage(hWnd, 5000, 5000, 5000);
if (i == 0)
MessageBox.Show("Window not found!");

[DllImport("coredll.dll")]
public extern static int SendMessage(IntPtr hwnd, uint msg, uint wParam,
uint lParam);
[DllImport("coredll.dll")]
public extern static int PostMessage(IntPtr hwnd, uint msg, uint wParam,
uint lParam);
[DllImport("coredll.dll", EntryPoint = "FindWindowW", CharSet =
CharSet.Unicode)]
public static extern IntPtr FindWindow(String strClass, String
strWindowName);

Can some one tell me how that can be done and any sample code showing how
it
can be done.

Thanks,
Murthy
 
G

Guest

Is FindWindow succeeding? Is the handle it's finding valid and the right
handle for your MessageWindow? Rather than asking for a solution, you'll
learn a lot more by figuring out why your code is failing.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Murthy said:
Hi,
I tried the following code in the receiving form.
But it is not receiving any message.
i have put a break point in wndproc but the control is not coming there.
In form load i created an instance of myMessageWindowClass....
But this is not working what is it that i am missing...

public class myMessageWindowClass : MessageWindow
{
// Assign integers to messages.
// Note that custom Window messages are after WM_USER = 0x400.
public const int WM_BOXUPDATE = 0x0401;
public const int WM_PNLUPDATE = 0x0402;


// Create an instance of the form.
MsgWindow updateform;

// Save reference to the form so it can
// be notified when messages are received.
public myMessageWindowClass(MsgWindow updateform)
{
this.updateform = updateform;
}

// Override the default WndProc behavior to examine messages.
protected override void WndProc(ref Message msg)
{
switch (msg.Msg)
{
}

// Call the base class WndProc for default message handling.
base.WndProc(ref msg);
}
}

Can someone give me a sample code that will receive any message posted to
it
from another application.

Thanks in Advance,
Murthy


Where's the receiving end code? Having just a send is like having a
phone
call with one phone - not too useful.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Murthy said:
Hi,
I want to post a windows message from one application and read it in
another
application.

I am using the below code to post a message to a form but i am not able
to
read the message in the receiving form in another application.

IntPtr hWnd;
hWnd = FindWindow(null, "MsgWindow");
int i = PostMessage(hWnd, 5000, 5000, 5000);
if (i == 0)
MessageBox.Show("Window not found!");

[DllImport("coredll.dll")]
public extern static int SendMessage(IntPtr hwnd, uint msg, uint
wParam,
uint lParam);
[DllImport("coredll.dll")]
public extern static int PostMessage(IntPtr hwnd, uint msg, uint
wParam,
uint lParam);
[DllImport("coredll.dll", EntryPoint = "FindWindowW", CharSet =
CharSet.Unicode)]
public static extern IntPtr FindWindow(String strClass, String
strWindowName);

Can some one tell me how that can be done and any sample code showing
how
it
can be done.

Thanks,
Murthy
 
G

Guest

Hi,
Sorry for the delay...I was out of town....

Yes the FindWindow is succeeding it is even returning an window handle and
is also posing a windows message. But i am not able to read it.
I even put a break point at WndProc ...It is not even receiving the OS
messages....

I tried to figure it out....also googled but could not find a solution.

Thanks in Advance,
Murthy

Is FindWindow succeeding? Is the handle it's finding valid and the right
handle for your MessageWindow? Rather than asking for a solution, you'll
learn a lot more by figuring out why your code is failing.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Murthy said:
Hi,
I tried the following code in the receiving form.
But it is not receiving any message.
i have put a break point in wndproc but the control is not coming there.
In form load i created an instance of myMessageWindowClass....
But this is not working what is it that i am missing...

public class myMessageWindowClass : MessageWindow
{
// Assign integers to messages.
// Note that custom Window messages are after WM_USER = 0x400.
public const int WM_BOXUPDATE = 0x0401;
public const int WM_PNLUPDATE = 0x0402;


// Create an instance of the form.
MsgWindow updateform;

// Save reference to the form so it can
// be notified when messages are received.
public myMessageWindowClass(MsgWindow updateform)
{
this.updateform = updateform;
}

// Override the default WndProc behavior to examine messages.
protected override void WndProc(ref Message msg)
{
switch (msg.Msg)
{
}

// Call the base class WndProc for default message handling.
base.WndProc(ref msg);
}
}

Can someone give me a sample code that will receive any message posted to
it
from another application.

Thanks in Advance,
Murthy


Where's the receiving end code? Having just a send is like having a
phone
call with one phone - not too useful.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Hi,
I want to post a windows message from one application and read it in
another
application.

I am using the below code to post a message to a form but i am not able
to
read the message in the receiving form in another application.

IntPtr hWnd;
hWnd = FindWindow(null, "MsgWindow");
int i = PostMessage(hWnd, 5000, 5000, 5000);
if (i == 0)
MessageBox.Show("Window not found!");

[DllImport("coredll.dll")]
public extern static int SendMessage(IntPtr hwnd, uint msg, uint
wParam,
uint lParam);
[DllImport("coredll.dll")]
public extern static int PostMessage(IntPtr hwnd, uint msg, uint
wParam,
uint lParam);
[DllImport("coredll.dll", EntryPoint = "FindWindowW", CharSet =
CharSet.Unicode)]
public static extern IntPtr FindWindow(String strClass, String
strWindowName);

Can some one tell me how that can be done and any sample code showing
how
it
can be done.

Thanks,
Murthy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top