【问题标题】:Setup project Window Handler in CustomActions class在 CustomActions 类中设置项目窗口处理程序
【发布时间】:2010-07-14 14:01:00
【问题描述】:

我有一个 CustomInstaller 类 (System.Configuration.Install.Installer),基本上我在 Install 方法中打开了一个对话框。 我想知道是否有可能以某种方式说该表单的“父”属性将是设置过程窗口?

我该怎么做?

【问题讨论】:

    标签: c# windows-installer custom-action


    【解决方案1】:

    您需要获取安装程序窗口的句柄。不太确定如何获得它,但 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();
            }
    

    【讨论】:

    • 我明白了...这是因为 Windows 安装程序在不同的进程中启动 CustomActions,但在同一棵树中...
    【解决方案2】:

    作为一个简单的补充,因为我寻找相同的答案以防止 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 成功了

    【讨论】:

      猜你喜欢
      • 2014-07-29
      • 1970-01-01
      • 2020-03-16
      • 1970-01-01
      • 2019-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多