0

I'm creating an Basic MSI installshield installer. And for choosing instllation path i'm calling FolderBrowserDialog. Everything works OK except FolderBrowserDialog appers in background. I would like to set it to be a foreground window. This code always returns true and works fine if there is no other window open.

How can I check if dialogHandle is my dialog handle?

Here is my method:

/// <param name="fPath">INSTALLPATH</param>
    /// <param name="handle">installshield handle</param>
    /// <returns></returns>
    public string NetworkFolderDialog(string sFilePath, IntPtr handle)
    {

        FolderBrowserDialog dialog = new FolderBrowserDialog();

        IntPtr handle2 = GetDesktopWindow();
        IntPtr dialogHandle = GetWindow(handle2, 5);

        bool set = SetForegroundWindow(dialogHandle);

        DialogResult result = dialog.ShowDialog();

        MessageBox.Show(set.ToString());

        if (result == DialogResult.OK)
            return dialog.SelectedPath;
        else
            return sFilePath;
    }

Thank you for your help.

Nejchy
  • 666
  • 11
  • 24

2 Answers2

0

I think you should remove the following lines from your code:

IntPtr handle2 = GetDesktopWindow();
IntPtr dialogHandle = GetWindow(handle2, 5);

bool set = SetForegroundWindow(dialogHandle);
Anax
  • 9,122
  • 5
  • 34
  • 68
  • I tried this. But it doesn't work at all. FolderBrowserDialog always appears behind install window. – Nejchy Sep 30 '09 at 10:47
  • Can you get the handle of the installation window? If so you can use the overloaded version of ShowDialog (dialog.ShowDialog(this)). – Anax Sep 30 '09 at 11:02
0

There is a discussion about this here: Custom Installer in .Net showing Form behind installer

Community
  • 1
  • 1
Cosmin
  • 21,216
  • 5
  • 45
  • 60