我正在使用SetWindowPos
和MoveWindow
调整窗口大小和居中。 它工作正常,但在Windows Media Player或控制面板等几个窗口,closures窗口并再次打开时,新的大小/移动不反映。 当我手动resize时,更改将在下次打开窗口时反映出来。 即使我调用UpdateWindow
,更改也不会反映出来。 有什么我需要发送窗口,使更改得到保存? RedrawWindow
帮助吗? 谢谢?
您应该使用GetWindowPlacement
和SetWindowPlacement
函数来检索和更改窗口的还原,最小化和最大化位置。 这可确保窗口大小由应用程序正确保存,以便在下次启动时恢复它们。
由于您使用的是C#,因此您需要从Windows API中调用这些函数:
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; }