Search code examples
c#windows-installercustom-action

Setup project Window Handler in CustomActions class


I have a CustomInstaller class (System.Configuration.Install.Installer) and basically I'm opening 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?


Solution

  • 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();
            }