I need to maximize a window in background, meaning without activating (focusing) it. SetWindowPlacement function doesn\'t offer this.. Any ideas?
WINDOWP
Try this using definitions from 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);
}
}
The trick is to change the window state with SetWindowLong and redraw it with SetWindowPosFlags.FrameChanged. And in your case with SetWindowPosFlags.DoNotActivate.