gpt4 book ai didi

c# - SetWindowPos/MoveWindow 持续存在问题

转载 作者:可可西里 更新时间:2023-11-01 11:22:04 39 4
gpt4 key购买 nike

我正在使用 SetWindowPosMoveWindow 来调整窗口大小和居中。它工作正常,但在 Windows Media Player 或控制面板等多个窗口上,当您关闭窗口并再次打开时,不会反射(reflect)新的调整大小/移动。当我手动调整大小时,更改会在我下次打开窗口时反射(reflect)出来。即使我调用 UpdateWindow,更改也不会反射(reflect)出来。是否需要发送窗口以保存更改? RedrawWindow 有帮助吗?谢谢?

最佳答案

您应该使用 GetWindowPlacement SetWindowPlacement 函数取而代之的是检索和更改窗口的恢复、最小化和最大化位置。这可确保应用程序正确保存窗口大小,以便在下次启动时恢复它们。

由于您使用的是 C#,因此您需要从 Windows API 中 P/调用这些函数:

const int SW_HIDE = 0;
const int SW_SHOWNORMAL = 1;
const int SW_SHOWMINIMIZED = 2;
const int SW_SHOWMAXIMIZED = 3;

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WINDOWPLACEMENT lpwndpl);

[StructLayout(LayoutKind.Sequential)]
struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}

[StructLayout(LayoutKind.Sequential)]
struct WINDOWPLACEMENT
{
public int length;
public int flags;
public int showCmd;
public Point ptMinPosition;
public Point ptMaxPosition;
public RECT rcNormalPosition;
}

关于c# - SetWindowPos/MoveWindow 持续存在问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4894065/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com