H
harvie wang
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
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