views:

125

answers:

1

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.

A: 

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

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

bool set = SetForegroundWindow(dialogHandle);
Anax
I tried this. But it doesn't work at all. FolderBrowserDialog always appears behind install window.
Nejchy
Can you get the handle of the installation window? If so you can use the overloaded version of ShowDialog (dialog.ShowDialog(this)).
Anax