我在这个应用程序中工作我将在应用程序1中等待一些事件,当这个事件发生时,我将发送消息给应用程序2,它将执行一些操作。广播窗口HWND_BROADCAST消息
首先API声明
private const int HWND_BROADCAST = 0xffff;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int RegisterWindowMessage(string lpString);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern bool SendNotifyMessage(int hWnd, int Msg, int wParam, int lParam);
申请代码1
private string msgstr = "MYMESSAGE";
public int msg = RegisterWindowMessage(msgstr);
if (msg == 0)
{
MessageBox.Show(Marshal.GetLastWin32Error().ToString());
}
//SendNotifyMessage(HWND_BROADCAST, msg, 4848484, 8484865);
SendNotifyMessage(HWND_BROADCAST, msg, 0, 0);
MessageBox.Show(Marshal.GetLastWin32Error().ToString());
应用2码
static readonly int msg = RegisterWindowMessage("MYMESSAGE");
protected override void WndProc(ref Message m)
{
if (m.Msg == msg)
{
MessageBox.Show(m.Msg.ToString() + " = from wndproc");
}
base.WndProc(ref m);
}
会有人指出这有什么代码问题。 我怀疑有问题SendNotifyMessage
wParam和lParam 参数
会有人给我建议任何其他的替代来实现这种行为!
什么是由UIPI和UAC是什么意思? – 2011-06-03 10:12:56
用户界面特权隔离(UIPI),用户帐户控制(UAC)。 UAC是你应该担心的一个问题,因为默认情况下应用程序在Vista +上运行“无特权”,因为我相信你知道,你是否以管理员身份运行你的应用程序? – 2011-06-03 10:18:08
是的,我正以管理员身份运行我的应用程序,我得到最后一个错误0.With out admin rights it returned 5.You are right。but still I did not receive on application 2. – 2011-06-03 10:20:05