【发布时间】:2010-07-14 14:01:00
【问题描述】:
我有一个 CustomInstaller 类 (System.Configuration.Install.Installer),基本上我在 Install 方法中打开了一个对话框。 我想知道是否有可能以某种方式说该表单的“父”属性将是设置过程窗口?
我该怎么做?
【问题讨论】:
标签: c# windows-installer custom-action
我有一个 CustomInstaller 类 (System.Configuration.Install.Installer),基本上我在 Install 方法中打开了一个对话框。 我想知道是否有可能以某种方式说该表单的“父”属性将是设置过程窗口?
我该怎么做?
【问题讨论】:
标签: c# windows-installer custom-action
您需要获取安装程序窗口的句柄。不太确定如何获得它,但 Process.GetCurrentProcess().MainWindowHandle 应该会给你很好的机会。然后创建一个 NativeWindow 来包装句柄,以便您可以将其用作所有者。像这样:
IntPtr hdl = Process.GetCurrentProcess().MainWindowHandle;
var window = new NativeWindow();
window.AssignHandle(hdl);
try {
using (var dlg = new YourForm()) {
var result = dlg.ShowDialog(window);
//...
}
}
finally {
window.ReleaseHandle();
}
【讨论】:
作为一个简单的补充,因为我寻找相同的答案以防止 MSI 主窗口与我的弹出窗口重叠:
var thatmsihandle = Process.GetCurrentProcess().Handle;
一个简单的包装是:
internal class WindowHandler
{
internal NativeWindow MainWindow { get; private set;}
internal WindowHandler()
{
MainWindow = new NativeWindow();
MainWindow.AssignHandle(Process.GetCurrentProcess().Handle);
}
internal void Dispose()
{
MainWindow.ReleaseHandle();
}
}
感谢您的指点,但还是节省了很多时间!
编辑:实际上它似乎不起作用,旧的 FindWindowA 成功了
【讨论】: