我有一個側杆的應用程序(對話運形成應用程序),其控制使用華廷自動化相關的IE瀏覽器。如何將窗口的Z-order設置爲剛好在激活的窗口下?
當側邊欄被激活時,我想也帶來相關的瀏覽器前進,但我不想贏得表格應用程序失去焦點。
我曾嘗試下面的代碼的許多設置/變化,但WinForms應用程序失去只要它被激活集中到瀏覽器,所以可以壓在表格上沒有任何按鍵!
private void BrowserControlForm_Activated(object sender, EventArgs e)
{
if (this.Browser != null)
{
SetWindowPos(this.Browser.hWnd, -1, this.Width, 0, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - this.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height, 0);
}
}
問:什麼是將其他窗口剛下(Z-爲了明智)當前激活(的WinForms)窗口的正確方法是什麼?
該示例代碼還會調整瀏覽器佔用屏幕的其餘部分,但這與問題無關。更多的現有代碼不會幫助解決問題。
更新:
SWP_NOACTIVATE失敗帶來的瀏覽器窗口前都:
SetWindowPos(this.CareCheckBrowser.hWnd, -1, this.Width, 0, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - this.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height, 0x0010 /*SWP_NOACTIVATE*/);
插入後的當前窗口的句柄還是失去焦點:
SetWindowPos(this.Browser.hWnd, (int)this.Handle, this.Width, 0, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - this.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height, 0);
設置當前窗口到瀏覽器不工作後,由於焦點已經丟失(因此按鈕點擊仍然是我) gnored)。焦點/激活筆觸剛上來回任何點擊例如爲:
SetWindowPos(this.Browser.hWnd, 0, this.Width, 0, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - this.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height, 0x0004);
SetForegroundWindow(this.Browser.hWnd);
SetForegroundWindow(this.Handle);
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.showwithoutactivation%28v=vs 0.110%29.aspx – 2014-09-01 15:46:49
@Hans帕桑特:這是一個'Form'方法。我需要提出獨立的IE瀏覽器實例。這可以應用於一個單獨的IE實例(我只有一個'hWnd')嗎? – 2014-09-01 15:48:42
然後,您需要SetWindowPos()的SWP_NOACTIVATE選項。 – 2014-09-01 15:49:55