我有一个侧杆的应用程序(对话运形成应用程序),其控制使用华廷自动化相关的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