use*_*240 1 .net c# windows winapi window-position
我正在使用SetWindowPos
并MoveWindow
调整窗口大小和居中。它可以正常工作,但是在Windows Media Player或“控制面板”等几个窗口上,当您关闭窗口并再次打开它时,新的调整大小/移动不会反映出来。手动调整大小时,更改将在下次打开窗口时反映出来。即使我打电话UpdateWindow
,更改也不会反映出来。我需要发送窗口以便保存更改吗?有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;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2779 次 |
最近记录: |