如何在后台最大化窗口?

我需要在背景中最大化窗口,这意味着不激活(聚焦)它。 SetWindowPlacement函数不提供此..任何想法?

WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); GetWindowPlacement(hwnd, ref wp); wp.showCmd = 3; SetWindowPlacement(hwnd, ref wp); 

我能找到的最好方法是(VB抱歉!);

 longForeHWnd = GetForegroundWindow Call ShowWindow(longBackHWnd, SW_SHOWMAXIMIZED) SetForegroundWindow (longForeHWnd) 

这只是一种解决方法,因为背景窗口(简要地)被激活,因此被提升为Z-Order

使用http://www.pinvoke.net中的定义尝试此操作:

 WINDOWPLACEMENT placement; if (GetWindowPlacement(hWnd, out placement)) { if ((GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) == 0) { var l = GetWindowLong(hWnd, GWL_STYLE); SetWindowLong(hWnd, GWL_STYLE, (l | WS_MAXIMIZE) & (~WS_MINIMIZE)); var maxPos = placement.MaxPosition; SetWindowPos(hWnd, IntPtr.Zero, maxPos.X, maxPos.Y, 0, 0, SetWindowPosFlags.AsynchronousWindowPosition | SetWindowPosFlags.DoNotActivate | SetWindowPosFlags.FrameChanged | SetWindowPosFlags.IgnoreResize | SetWindowPosFlags.IgnoreZOrder); } } 

诀窍是使用SetWindowLong更改窗口状态,并使用SetWindowPosFlags.FrameChanged重绘它。 在你的情况下使用SetWindowPosFlags.DoNotActivate。

请在加载Windows时使用以下代码

  private void Form1_Load(object sender, EventArgs e) { this.WindowState = FormWindowState.Maximized; } 

这将最大化您的窗口