無効なサイズ変更機能(WindowStyle = None、ResizeMode = CanMinimize)を使用したWPFウィンドウがあります。ShowWindow関数呼び出しに対するウィンドウの反応を無効にします。
1つの状況を除いて、正常に動作します。 SW_MAXIMIZEオプションを使用してウィンドウ上にWIN API関数ShowWindowを呼び出すアプリケーション(つまりAutoHotKey)があれば、サイズ変更を行わずにデスクトップ上でウィンドウの位置を(0、0)に戻し、ユーザーは画面上をさらに移動することができません。
この動作を無効にするにはどうすればよいですか?窓がこの窓を無視するようにしたい。
私はWM_WINDOWPOSCHANGINGイベントに反応しようとしましたが、これはユーザーがウィンドウを最小化するまで動作します。最小化されて復元された後、再び(0、0)座標に再配置されます。
private IntPtr ProcessMessage(IntPtr windowHandle, int msg, IntPtr wideParam, IntPtr leftParam, ref bool handled)
{
Msg windowsMessage = (Msg)msg;
switch (windowsMessage)
{
case Msg.WM_WINDOWPOSCHANGING:
{
WindowPos windowPos = (WindowPos)Marshal.PtrToStructure(leftParam, typeof(WindowPos));
if (IsNoClientAction(windowPos) && !IsMinimizing(windowPos) && window.WindowState == WindowState.Normal)
{
windowPos.Flags = SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOMOVE;
handled = true;
Marshal.StructureToPtr(windowPos, leftParam, true);
}
break;
}
}
return IntPtr.Zero;
}
private static bool IsNoClientAction(WindowPos windowPos)
{
return (windowPos.Flags & SetWindowPosFlags.SWP_NOCLIENTSIZE) != 0 || (windowPos.Flags & SetWindowPosFlags.SWP_NOCLIENTMOVE) != 0;
}
private static bool IsMinimizing(WindowPos windowPos)
{
return windowPos.Left == -32000 && windowPos.Top == -32000;
}