ウィンドウのサイズを変更して中央に配置するためにSetWindowPos
andを使用しています。MoveWindow
正常に動作しますが、Windows Media Player やコントロール パネルなどのいくつかのウィンドウで、ウィンドウを閉じて再度開くと、新しいサイズ変更/移動が反映されません。手動でサイズを変更すると、次にウィンドウを開いたときに変更が反映されます。を呼び出しUpdateWindow
ても変更が反映されません。変更が保存されるようにウィンドウを送信する必要があるものはありますか? 役に立ちますかRedrawWindow
?ありがとう?
3828 次
1 に答える
5
ウィンドウの復元、最小化、および最大化された位置を取得および変更するには、代わりに 関数GetWindowPlacement
と関数を使用する必要があります。SetWindowPlacement
これにより、ウィンドウ サイズがアプリケーションによって適切に保存され、次回の起動時に復元できるようになります。
C# を使用しているため、Windows API からこれらの関数を P/Invoke する必要があります。
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;
}
于 2011-02-04T05:12:58.250 に答える