473,761 Members | 8,933 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.ToStri ng()); break;
}
base.WndProc(re f m);
}
private void button1_Click(o bject sender, System.EventArg s e)
{
try
{
IntPtr nullhandle = IntPtr.Zero;
int i = SendMessage((in t)this.Handle,W M_test,0,0);
//send ok,i == 1,popup messagebox
int i = SendMessage((in t)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 11143
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.co m

"harvie wang" <qu*****@gmail. com> wrote in message
news:5e******** *************** ***@news.micros oft.com...

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.ToStri ng()); break; }
base.WndProc(re f m);
}
private void button1_Click(o bject sender, System.EventArg s e)
{
try
{
IntPtr nullhandle = IntPtr.Zero;
int i = SendMessage((in t)this.Handle,W M_test,0,0);
//send ok,i == 1,popup messagebox
int i = SendMessage((in t)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.micros oft.com...

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.ToStri ng()); break; }
base.WndProc(re f m);
}
private void button1_Click(o bject sender, System.EventArg s e)
{
try
{
IntPtr nullhandle = IntPtr.Zero;
int i = SendMessage((in t)this.Handle,W M_test,0,0);
//send ok,i == 1,popup messagebox
int i = SendMessage((in t)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.micros oft.com...
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.ToStri ng()); break; }
base.WndProc(re f m);
}
private void button1_Click(o bject sender, System.EventArg s e)
{
try
{
IntPtr nullhandle = IntPtr.Zero;
int i = SendMessage((in t)this.Handle,W M_test,0,0);
//send ok,i == 1,popup messagebox
int i = SendMessage((in t)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.co m

"harvie wang" <qu*****@gmail. com> wrote in message
news:5e******** *************** ***@news.micros oft.com...
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.micros oft.com...
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.ToStri ng()); break; }
base.WndProc(re f m);
}
private void button1_Click(o bject sender, System.EventArg s e)
{
try
{
IntPtr nullhandle = IntPtr.Zero;
int i = SendMessage((in t)this.Handle,W M_test,0,0);
//send ok,i == 1,popup messagebox
int i = SendMessage((in t)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.micros oft.com...
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.micros oft.com...

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.ToStri ng()); break; }
base.WndProc(re f m);
}
private void button1_Click(o bject sender, System.EventArg s e)
{
try
{
IntPtr nullhandle = IntPtr.Zero;
int i = SendMessage((in t)this.Handle,W M_test,0,0);
//send ok,i == 1,popup messagebox
int i = SendMessage((in t)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.MyCustomEv ent += new EventHandler(th is.OnFormAMyCus tomEvent);

OnFormAMyCustom Event 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.MyCustomEv ent;

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

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

"harvie wang" <qu*****@gmail. com> wrote in message
news:5e******** *************** ***@news.micros oft.com...
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.micros oft.com...
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.micros oft.com...

> 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.ToStri ng()); break; }
> base.WndProc(re f m);
> }
> private void button1_Click(o bject sender, System.EventArg s e)
> {
> try
> {
> IntPtr nullhandle = IntPtr.Zero;
> int i = SendMessage((in t)this.Handle,W M_test,0,0);
> //send ok,i == 1,popup messagebox
> int i = SendMessage((in t)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
4991
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 POSTERS: Please use comp.lang.php for PHP related questions, alt.php* groups are not recommended.
1
5670
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 main window is brought to front, child should also be brought to front, etc. Thx, Piotrek Stachowicz
0
1289
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 sockets recievs any messages it should pop a message about it even the user is actively working on some other Form other than the form which has the socket instatnce.(which is handled through a delegate in the Form)
4
28453
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 recipients and leave it there for the user to finish filling out. What classes am I looking for?
3
7695
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 (which loads an applet. Call this SubChild). This is for the first time. Now if i go ahead and click on the link in the Parent window, the Child and the Subchild windows are refreshed. None of the windows are closed. Now if i refresh the Parent...
2
1328
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 idea will be appreciate able.
3
100080
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 creation (or any web page for that matter) is to use Safari. Follow these four easy steps. 1. Create the HTML Layout your HTML code including any images or graphics you'd like to include. In this example, we will make a simple birthday email to add...
4
1028
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? Or is that just something they wrote for themselves? It looks pretty neat and I'd like to use it if it is available. Thanks,
12
14428
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 be precise I use a Fortran DLL which passes its messages through a VBA callback function, but I don't think it's important for the problem. The problem is that once I focus on another application, MS Access freezes itself. I mean, when I come back...
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9988
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9923
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7358
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.