Setup project Window Handler in CustomActions class
I have a CustomInstaller class (System.Configuration.Install.Installer) and basically I'm op开发者_如何转开发ening a dialog form at Install method. I wonder if it's possible somehow to say that 'Parent' property of that form would be the setup process window?
How can I do that?
You need to get the handle of the installer window. Not so sure how to get it, but Process.GetCurrentProcess().MainWindowHandle ought to give you good odds. Then create a NativeWindow to wrap the handle so you can use it as the owner. Like this:
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();
}
As a simple complement since I looked for the same answer to prevent the MSI main window to overlap my popup:
var thatmsihandle = Process.GetCurrentProcess().Handle;
An easy wrapper would be:
internal class WindowHandler
{
internal NativeWindow MainWindow { get; private set;}
internal WindowHandler()
{
MainWindow = new NativeWindow();
MainWindow.AssignHandle(Process.GetCurrentProcess().Handle);
}
internal void Dispose()
{
MainWindow.ReleaseHandle();
}
}
Thanks for the pointer nonetheless saved a lot of time!
EDIT: it seems not to work in fact, good old FindWindowA did the trick
精彩评论