0

我需要在后台最大化一个窗口,这意味着不激活(聚焦)它。SetWindowPlacement 函数不提供此功能。有什么想法吗?

        WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
        GetWindowPlacement(hwnd, ref wp);

        wp.showCmd = 3;
        SetWindowPlacement(hwnd, ref wp);
4

3 回答 3

1

我能找到的最好方法是(VB对不起!);

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

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

于 2013-11-11T21:47:29.983 回答
1

尝试使用来自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。

于 2014-04-27T08:58:55.360 回答
-1

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

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

    }

这将最大化您的窗口

于 2012-11-17T14:42:17.550 回答