我正在尝试将自定义消息从提升的设置(在 Windows 7 上)发送到用 C# 编写的正在运行的应用程序。
不幸的是,在 C# 应用程序中从未收到此消息。
这是因为安装程序和应用程序在不同的用户下运行吗?我该如何解决这个问题?
为方便起见:
// --- C# code ---
private const int WM_CUSTOM_CLOSE = 0x400 + 0x500;
private const int CUSTOM_CLOSE_WPARAM = 0x1;
private const int CUSTOM_CLOSE_LPARAM = 0x2;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_CUSTOM_CLOSE)
{
int wp = m.WParam.ToInt32();
int lp = m.LParam.ToInt32();
if (wp == CUSTOM_CLOSE_WPARAM && lp == CUSTOM_CLOSE_LPARAM)
{
Debug.WriteLine("Close application");
Close();
}
}
base.WndProc(ref m);
}
// --- INNO SETUP code ---
const
WM_USER = $400;
WM_CUSTOM_CLOSE = WM_USER + $500;
WM_CUSTOM_WPARAM = $1;
WM_CUSTOM_LPARAM = $2;
function InitializeSetup(): Boolean;
begin
SendNotifyMessage(HWND_BROADCAST, WM_CUSTOM_CLOSE,
WM_CUSTOM_WPARAM, WM_CUSTOM_LPARAM);
end;