2009-09-30 51 views
0

我正在創建一個Basic MSI installshield安裝程序。並選擇instllation路徑我打電話給FolderBrowserDialog。一切正常,除了FolderBrowserDialog在後臺出現。我想將它設置爲前景窗口。如果沒有其他窗口打開,此代碼始終返回true並正常工作。將FolderBrowserDialog設置爲前景

如何檢查dialogHandle是否是我的對話框?

這裏是我的方法:

/// <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; 
    } 

謝謝您的幫助。

回答

0

我想你應該從你的代碼中刪除以下行:

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

bool set = SetForegroundWindow(dialogHandle); 
+0

我嘗試這樣做。但它根本不起作用。 FolderBrowserDialog總是出現在安裝窗口的後面。 – Nejchy 2009-09-30 10:47:30

+0

你能得到安裝窗口的句柄嗎?如果是這樣,你可以使用ShowDialog的重載版本(dialog.ShowDialog(this))。 – Anax 2009-09-30 11:02:32