Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Does anybody know how to send messages and receive messages in C# ?

0 views
Skip to first unread message

Wilson Wei

unread,
Sep 25, 2001, 1:23:13 AM9/25/01
to
HI,guys

Does anybody know how to send messages and receive messages in C# ?
Thanks a lot !

--
Wason


Justin Rogers

unread,
Sep 25, 2001, 2:35:54 AM9/25/01
to
Far too broad of a question Wei, you'll have to be more specific in what
your talking about. Sending and receiving messages can be done with a UDP
chat type of client, a TCP chat type of client, a Web Service, Using simple
web pages, Message queues, rpc, pipes, the list goes on. You'll have to be
WAY more specific.

--
Justin Rogers
jus...@mlstoday.com
digi...@hotmail.com

"Wilson Wei" <P...@DZXX.COM> wrote in message
news:#11FgLYRBHA.1460@tkmsftngp04...

Wilson Wei

unread,
Sep 25, 2001, 2:40:03 AM9/25/01
to
Hi,Rogers

Thanks for the speedy reply. My problem is, how to use the
SendMessage(..) API function in C# Winform.

--
Wilson

"Justin Rogers" <jus...@mlstoday.com> wrote in message
news:#gL6otYRBHA.1508@tkmsftngp04...

Justin Rogers

unread,
Sep 25, 2001, 3:02:27 AM9/25/01
to
Boy, first that is pretty advanced, and I'd recommend Michael Harsh for the
answer, but he might not check this group. So repost on the WindowsForms
newsgroup. However, I can offer some small guidance. In order to send
messages you can create the new Message object and pass that to the
PreProcessMessage method. If you need to trap custom messages in your C#
programs then you can override the WndProc method which gets passed a
Message object. If you don't handle the message then simply calls
base.WndProc(msg) with the message to pass it to the parent control.

Simple as pie really, but I'm sure there are some Gotchas. Mainly because I
think PreProcessMessage traps a lot of normal messages and hands them to
other functions or calls events, but I'm not sure of the list of said
messages.

"Wilson Wei" <P...@DZXX.COM> wrote in message

news:OffIa2YRBHA.320@tkmsftngp03...

Wilson Wei

unread,
Sep 25, 2001, 3:31:15 AM9/25/01
to
Rogers,
Thanks for your replies !
I'll try it!

--
Wilson

"Justin Rogers" <jus...@mlstoday.com> wrote in message

news:Ov2ld8YRBHA.1972@tkmsftngp04...

Magnus Lindberg

unread,
Sep 25, 2001, 7:51:23 AM9/25/01
to
I wrote a tutorial on using SendMessage to manipulate WinAmp a while ago. Maybe that'll help you out?

http://www.cshrp.net/content.aspx?showID=497

I don't know how to recieve messages though.

--
Magnus Lindberg
cshrp.net - Elegant code by witty programmers

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Wilson Wei

unread,
Sep 25, 2001, 9:28:37 AM9/25/01
to
Hi,all

Congratulations!! I've solved the problem !
Thanks for Rogers and Lindberg ,thank you very much !
Attach my codes below:
------------------------------------
/////////////////////////////////////////
///file name: Note.cs
///
public class Note
{
[DllImport("User32.dll",EntryPoint="SendMessage")]
private static extern int SendMessage(
int hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
[DllImport("User32.dll",EntryPoint="FindWindow")]
private static extern int FindWindow(string lpClassName,string
lpWindowName);
//For Messaging
public const int USER = 0x500;
public const int TEST = USER + 1;
private void SendMsgToMainForm(int MSG)
{
int WINDOW_HANDLER = FindWindow(null,@"Kingsoft Notes - List");
if(WINDOW_HANDLER == 0)
{
throw new Exception("Could not find Main window!");
}
SendMessage(WINDOW_HANDLER,MSG,100,200);
}

}


/////////////////////////////////////////
/// File name : Form1.cs
///
public class Form1 : System.Windows.Forms.Form
{
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent
call
//
}
/// Override the DefWndProc of Form1
protected override void DefWndProc(ref System.Windows.Forms.Message m)
{
switch(m.Msg)
{
case Note.USER:
string message = string.Format ("Received message!
parameters are :{0},{1}",m.WParam ,m.LParam);
MessageBox.Show (message);
break;
default:
base.DefWndProc(ref m);
break;
}
//Console.WriteLine(m.LParam);
}

--
Wilson Wei


0 new messages