I need to maximize a window in background, meaning without activating (focusing) it. SetWindowPlacement function doesn\'t offer this.. Any ideas?
WINDOWP
Please use the below code at the time of windows load
private void Form1_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
}
This will maximise your window
The best way I could find to do this was (VB sorry!);
longForeHWnd = GetForegroundWindow
Call ShowWindow(longBackHWnd, SW_SHOWMAXIMIZED)
SetForegroundWindow (longForeHWnd)
This is only a work-around because the Background Window is (briefly) activated and so gets promoted up the Z-Order
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.