J
Jeremy Chapman
I start up several instances of an application I've written. From one of
the applications I'm trying to close all of them, but it's not working. I'm
doing this by registering a message and broadcasting it. but when I put a
breakpoint in my overridden WndProc, It never seems to get the message.
public class frmMyApplication : System.Windows.Forms.Form
{
public const int HWND_BROADCAST = 0xFFFF;
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int RegisterWindowMessage(string strMessageType);
[System.Runtime.InteropServices.DllImport(strUSER32DLL,
CharSet=CharSet.Auto, SetLastError=true)]
public static extern int SendMessage(IntPtr
hWnd,[MarshalAs(UnmanagedType.U4)] int iMsg, int iWParam, int iLParam);
int iCloseAllMessage_m;
public frmMyApplication()
{
iCloseAllMessage_m = MediScript.RegisterWindowMessage("_CloseMyApps");
if (iCloseAllMessage_m == 0)
{
throw new Exception("RegisterWindowMessage returned 0");
}
}
protected override void WndProc(ref Message m)
{
if (iCloseAllMessage_m != 0 && m.Msg == iCloseAllMessage_m)
{
Application.Exit();
}
else
{
base.WndProc (ref m);
}
}
private void mnuiCloseAll_Click(object sender, System.EventArgs e)
{
SendMessage((IntPtr)HWND_BROADCAST, iCloseAllMessage_m, 0,0);
}
}
the applications I'm trying to close all of them, but it's not working. I'm
doing this by registering a message and broadcasting it. but when I put a
breakpoint in my overridden WndProc, It never seems to get the message.
public class frmMyApplication : System.Windows.Forms.Form
{
public const int HWND_BROADCAST = 0xFFFF;
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int RegisterWindowMessage(string strMessageType);
[System.Runtime.InteropServices.DllImport(strUSER32DLL,
CharSet=CharSet.Auto, SetLastError=true)]
public static extern int SendMessage(IntPtr
hWnd,[MarshalAs(UnmanagedType.U4)] int iMsg, int iWParam, int iLParam);
int iCloseAllMessage_m;
public frmMyApplication()
{
iCloseAllMessage_m = MediScript.RegisterWindowMessage("_CloseMyApps");
if (iCloseAllMessage_m == 0)
{
throw new Exception("RegisterWindowMessage returned 0");
}
}
protected override void WndProc(ref Message m)
{
if (iCloseAllMessage_m != 0 && m.Msg == iCloseAllMessage_m)
{
Application.Exit();
}
else
{
base.WndProc (ref m);
}
}
private void mnuiCloseAll_Click(object sender, System.EventArgs e)
{
SendMessage((IntPtr)HWND_BROADCAST, iCloseAllMessage_m, 0,0);
}
}