473,498 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to send message to all window(include child window)


Hi,

How to send a message to every window(include child window),
I use SendMessage ,but It can't do that.

class frmA
{
public const int WM_test = 0x400 + 1;
protected override void WndProc(ref Message m)
{
// Listen for operating system messages.
switch (m.Msg)
{
case WM_test:
MessageBox.Show(WM_test.ToString()); break;
}
base.WndProc(ref m);
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
IntPtr nullhandle = IntPtr.Zero;
int i = SendMessage((int)this.Handle,WM_test,0,0);
//send ok,i == 1,popup messagebox
int i = SendMessage((int)nullhandle,WM_test,0,0);
//i == 0,do nothing
}
catch(Exception ep)
{
MessageBox.Show(ep.Message);
}
}
}

void func()
{
frmA frmTestA = new frmA();
frmA frmTestB = new frmA();
frmTestA.show();
frmTestB.show();
}
//now when i push the frmTestA button1,I want to send the WM_test msg to
frmTestA and frmTestB,how to do this?
Is there any designed patterns can implement my request?

best regarsd,

Harvie
Nov 17 '05 #1
6 11124
Harvie,

Sending a message to ALL windows in an application will be incredibly
inefficient. Rather, you should send a message to one control, which knows
the controls it has to send the message to, and then do that.

Or, since you are working in windows forms, why not just have an event
off your main form (or whatever is firing the event, or a class which acts
as a manager) and have subscribers subscribe to it as needed?

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"harvie wang" <qu*****@gmail.com> wrote in message
news:5e**************************@news.microsoft.c om...

Hi,

How to send a message to every window(include child window),
I use SendMessage ,but It can't do that.

class frmA
{
public const int WM_test = 0x400 + 1;
protected override void WndProc(ref Message m) {
// Listen for operating system messages.
switch (m.Msg)
{
case WM_test:
MessageBox.Show(WM_test.ToString()); break; }
base.WndProc(ref m);
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
IntPtr nullhandle = IntPtr.Zero;
int i = SendMessage((int)this.Handle,WM_test,0,0);
//send ok,i == 1,popup messagebox
int i = SendMessage((int)nullhandle,WM_test,0,0);
//i == 0,do nothing
}
catch(Exception ep)
{
MessageBox.Show(ep.Message);
}
}
}

void func()
{
frmA frmTestA = new frmA();
frmA frmTestB = new frmA();
frmTestA.show();
frmTestB.show();
}
//now when i push the frmTestA button1,I want to send the WM_test msg to
frmTestA and frmTestB,how to do this?
Is there any designed patterns can implement my request?

best regarsd,

Harvie

Nov 17 '05 #2
Hi,

Out of curiosity, Why you want to do that?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"harvie wang" <qu*****@gmail.com> wrote in message
news:5e**************************@news.microsoft.c om...

Hi,

How to send a message to every window(include child window),
I use SendMessage ,but It can't do that.

class frmA
{
public const int WM_test = 0x400 + 1;
protected override void WndProc(ref Message m) {
// Listen for operating system messages.
switch (m.Msg)
{
case WM_test:
MessageBox.Show(WM_test.ToString()); break; }
base.WndProc(ref m);
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
IntPtr nullhandle = IntPtr.Zero;
int i = SendMessage((int)this.Handle,WM_test,0,0);
//send ok,i == 1,popup messagebox
int i = SendMessage((int)nullhandle,WM_test,0,0);
//i == 0,do nothing
}
catch(Exception ep)
{
MessageBox.Show(ep.Message);
}
}
}

void func()
{
frmA frmTestA = new frmA();
frmA frmTestB = new frmA();
frmTestA.show();
frmTestB.show();
}
//now when i push the frmTestA button1,I want to send the WM_test msg to
frmTestA and frmTestB,how to do this?
Is there any designed patterns can implement my request?

best regarsd,

Harvie

Nov 17 '05 #3
Hi,cheers
In frmTestA window,I create a map,when mouse move on it,I want another
frmTestB window map move mouse,so I want to implement it by sendmessage on
map_mousemove(),

I think the Observer pattern can do it,but I want to know how to implement
by use sendmessage .

thanks!

Harvie
Hello Ignacio Machin ( .NET/ C# MVP )" ignacio.machin AT dot.state.fl.us,
Hi,

Out of curiosity, Why you want to do that?

cheers,

"harvie wang" <qu*****@gmail.com> wrote in message
news:5e**************************@news.microsoft.c om...
Hi,

How to send a message to every window(include child window), I use
SendMessage ,but It can't do that.

class frmA
{
public const int WM_test = 0x400 + 1;
protected override void WndProc(ref Message m) {
// Listen for operating system messages.
switch (m.Msg)
{
case WM_test:
MessageBox.Show(WM_test.ToString()); break; }
base.WndProc(ref m);
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
IntPtr nullhandle = IntPtr.Zero;
int i = SendMessage((int)this.Handle,WM_test,0,0);
//send ok,i == 1,popup messagebox
int i = SendMessage((int)nullhandle,WM_test,0,0);
//i == 0,do nothing
}
catch(Exception ep)
{
MessageBox.Show(ep.Message);
}
}
}
void func()
{
frmA frmTestA = new frmA();
frmA frmTestB = new frmA();
frmTestA.show();
frmTestB.show();
}
//now when i push the frmTestA button1,I want to send the WM_test msg
to
frmTestA and frmTestB,how to do this?
Is there any designed patterns can implement my request?
best regarsd,

Harvie

Nov 17 '05 #4
Harvie,

You really should expose an event from frmTestA, and then have frmTestB
subscribe to the event. Sending a window message to every window in your
application is a HUGE waste of resources.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"harvie wang" <qu*****@gmail.com> wrote in message
news:5e**************************@news.microsoft.c om...
Hi,cheers
In frmTestA window,I create a map,when mouse move on it,I want another
frmTestB window map move mouse,so I want to implement it by sendmessage on
map_mousemove(),

I think the Observer pattern can do it,but I want to know how to
implement by use sendmessage .

thanks!

Harvie
Hello Ignacio Machin ( .NET/ C# MVP )" ignacio.machin AT dot.state.fl.us,
Hi,

Out of curiosity, Why you want to do that?

cheers,

"harvie wang" <qu*****@gmail.com> wrote in message
news:5e**************************@news.microsoft.c om...
Hi,

How to send a message to every window(include child window), I use
SendMessage ,but It can't do that.

class frmA
{
public const int WM_test = 0x400 + 1;
protected override void WndProc(ref Message m) {
// Listen for operating system messages.
switch (m.Msg)
{
case WM_test:
MessageBox.Show(WM_test.ToString()); break; }
base.WndProc(ref m);
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
IntPtr nullhandle = IntPtr.Zero;
int i = SendMessage((int)this.Handle,WM_test,0,0);
//send ok,i == 1,popup messagebox
int i = SendMessage((int)nullhandle,WM_test,0,0);
//i == 0,do nothing
}
catch(Exception ep)
{
MessageBox.Show(ep.Message);
}
}
}
void func()
{
frmA frmTestA = new frmA();
frmA frmTestB = new frmA();
frmTestA.show();
frmTestB.show();
}
//now when i push the frmTestA button1,I want to send the WM_test msg
to
frmTestA and frmTestB,how to do this?
Is there any designed patterns can implement my request?
best regarsd,

Harvie


Nov 17 '05 #5
Hello Nicholas Paldino [.NET/C# MVP],
thanks:)
I do not understand your means.
would you give me a sample codes,to implement the event?

thanks very much!

Harvie

Harvie,

You really should expose an event from frmTestA, and then have
frmTestB subscribe to the event. Sending a window message to every
window in your application is a HUGE waste of resources.

"harvie wang" <qu*****@gmail.com> wrote in message
news:5e**************************@news.microsoft.c om...
Hi,cheers
In frmTestA window,I create a map,when mouse move on it,I want
another
frmTestB window map move mouse,so I want to implement it by
sendmessage on
map_mousemove(),
I think the Observer pattern can do it,but I want to know how to
implement by use sendmessage .

thanks!

Harvie

Hello Ignacio Machin ( .NET/ C# MVP )" ignacio.machin AT
dot.state.fl.us,
Hi,

Out of curiosity, Why you want to do that?

cheers,

"harvie wang" <qu*****@gmail.com> wrote in message
news:5e**************************@news.microsoft.c om...

Hi,

How to send a message to every window(include child window), I use
SendMessage ,but It can't do that.

class frmA
{
public const int WM_test = 0x400 + 1;
protected override void WndProc(ref Message m) {
// Listen for operating system messages.
switch (m.Msg)
{
case WM_test:
MessageBox.Show(WM_test.ToString()); break; }
base.WndProc(ref m);
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
IntPtr nullhandle = IntPtr.Zero;
int i = SendMessage((int)this.Handle,WM_test,0,0);
//send ok,i == 1,popup messagebox
int i = SendMessage((int)nullhandle,WM_test,0,0);
//i == 0,do nothing
}
catch(Exception ep)
{
MessageBox.Show(ep.Message);
}
}
}
void func()
{
frmA frmTestA = new frmA();
frmA frmTestB = new frmA();
frmTestA.show();
frmTestB.show();
}
//now when i push the frmTestA button1,I want to send the WM_test
msg
to
frmTestA and frmTestB,how to do this?
Is there any designed patterns can implement my request?
best regarsd,
Harvie

Nov 17 '05 #6
Harvie,

It's simple. frmTestA does this:

// Expose the event.
public event EventHandler MyCustomEvent;

When you want to subscribe to the event, frmTestB does this:

// frmA is an INSTANCE of frmTestA, so you have to pass it to the instance
// of frmTestB
frmA.MyCustomEvent += new EventHandler(this.OnFormAMyCustomEvent);

OnFormAMyCustomEvent is the method you want executed when frmTestA fires
it's event.

In frmTestA, when you want to fire the event, you do this:

// Assign the event handlers to a temp variable.
EventHandler temp = this.MyCustomEvent;

// Fire if there are events.
if (temp != null)
temp(this, EventArgs.Empty);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"harvie wang" <qu*****@gmail.com> wrote in message
news:5e**************************@news.microsoft.c om...
Hello Nicholas Paldino [.NET/C# MVP],
thanks:)
I do not understand your means.
would you give me a sample codes,to implement the event?

thanks very much!

Harvie

Harvie,

You really should expose an event from frmTestA, and then have
frmTestB subscribe to the event. Sending a window message to every
window in your application is a HUGE waste of resources.

"harvie wang" <qu*****@gmail.com> wrote in message
news:5e**************************@news.microsoft.c om...
Hi,cheers
In frmTestA window,I create a map,when mouse move on it,I want
another
frmTestB window map move mouse,so I want to implement it by
sendmessage on
map_mousemove(),
I think the Observer pattern can do it,but I want to know how to
implement by use sendmessage .

thanks!

Harvie

Hello Ignacio Machin ( .NET/ C# MVP )" ignacio.machin AT
dot.state.fl.us,

Hi,

Out of curiosity, Why you want to do that?

cheers,

"harvie wang" <qu*****@gmail.com> wrote in message
news:5e**************************@news.microsoft.c om...

> Hi,
>
> How to send a message to every window(include child window), I use
> SendMessage ,but It can't do that.
>
> class frmA
> {
> public const int WM_test = 0x400 + 1;
> protected override void WndProc(ref Message m) {
> // Listen for operating system messages.
> switch (m.Msg)
> {
> case WM_test:
> MessageBox.Show(WM_test.ToString()); break; }
> base.WndProc(ref m);
> }
> private void button1_Click(object sender, System.EventArgs e)
> {
> try
> {
> IntPtr nullhandle = IntPtr.Zero;
> int i = SendMessage((int)this.Handle,WM_test,0,0);
> //send ok,i == 1,popup messagebox
> int i = SendMessage((int)nullhandle,WM_test,0,0);
> //i == 0,do nothing
> }
> catch(Exception ep)
> {
> MessageBox.Show(ep.Message);
> }
> }
> }
> void func()
> {
> frmA frmTestA = new frmA();
> frmA frmTestB = new frmA();
> frmTestA.show();
> frmTestB.show();
> }
> //now when i push the frmTestA button1,I want to send the WM_test
> msg
> to
> frmTestA and frmTestB,how to do this?
> Is there any designed patterns can implement my request?
> best regarsd,
> Harvie
>


Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4970
by: Justin Koivisto | last post by:
Is there a way to create an alert-like message box that uses a custom image? Basically, I want to replace the default ! image with something else. -- Justin Koivisto - spam@koivi.com PHP...
1
5645
by: Piotrek Stachowicz | last post by:
Hi, I've got two windows: main one (visible in task bar) and, the other one which is created by main (not visible in task bar). Now, how can I make the "child" window obey his parent, i.e. when...
0
1275
by: chathurangakw | last post by:
Hi , I'm working on a smart client application. In one of my forms I have a socket instance which listens for any messages from others and there are some other windows forms too. when the...
4
28433
by: Andy | last post by:
Hi, I have a C# application and I'd like it to use Outlook 2003 to send messages. I don't want to send them programmaticlly though; I just want to open the New Messge window, set the...
3
7675
by: hussain123 | last post by:
We have a main window (call it Parent). Clicking on a link in the main window will open up another IE window (Child) using the loadInFrame() method. In the Child window, i load another IE window...
2
1305
by: CyberSoftHari | last post by:
I want to show a reminder message in my application and which should always visible, even user click some other application. (i.e.) other application window should not hide my message window. Any...
3
99944
digicrowd
by: digicrowd | last post by:
http://bytes.com/images/howtos/applemail_sig_icon.jpg You can make your emails fancy in Mail.app by using Rich Text formatting or even included Stationery. But, a simple way to send your own HTML...
4
1009
by: tshad | last post by:
I noticed that a couple of apps (outlook, Citrix) create a small blue message window above the toolbar that fades in for about 10 seconds than fades out. Is that a object we can use in VS 2008? ...
12
14377
by: bnono | last post by:
Hi all, I developed some VBA code in MS Access 2003, and during execution I print messages indicating the overall progress in a textbox of the active form (and also in the bottom status bar). To...
0
7205
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.