我有一个CustomInstaller类(System.Configuration.Install.Installer),基本上我在Install方法中打开一个对话框窗体。 我不知道是否有可能说这个窗体的'Parent'属性是设置过程窗口?安装项目CustomActions类中的窗口处理程序
我该怎么做?
我有一个CustomInstaller类(System.Configuration.Install.Installer),基本上我在Install方法中打开一个对话框窗体。 我不知道是否有可能说这个窗体的'Parent'属性是设置过程窗口?安装项目CustomActions类中的窗口处理程序
我该怎么做?
您需要获取安装程序窗口的句柄。不太确定如何得到它,但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没有窍门
它作为MainWindowHandler返回零。我想知道为什么... – Agzam 2010-07-14 15:31:09
我明白了......这是因为Windows Installer在不同的进程启动CustomActions,但在同一棵树中... – Agzam 2010-07-14 15:36:27