简体   繁体   English

如何在 Windows 上防止全屏/半屏

[英]How to prevent fullscreen/halfscreen on Windows

I am developing a single-window app on Windows with Unity.我正在使用 Unity 在 Windows 上开发单窗口应用程序。
I allow a user to resize the window but the aspect ratio must be kept.我允许用户调整窗口大小,但必须保持纵横比。
I want to prevent fullscreen and halfscreen, because they break the aspect ratio.我想防止全屏和半屏,因为它们破坏了纵横比。

I've found the following operations make an app fullscreen or halfscreen.我发现以下操作可以使应用程序全屏或半屏。

  • fullscreen:全屏:
    • clicking a maximize button on the title bar单击标题栏上的最大化按钮
    • dragging the window to top of screen将窗口拖到屏幕顶部
    • pressing Alt + Enter key按 Alt + Enter 键
    • pressing Windows + Up-Arrow key按 Windows + 向上箭头键
  • halfscreen:半屏:
    • dragging the window to left/right of screen将窗口拖动到屏幕的左侧/右侧
    • pressing Windows + Left/Right -Arrow key按 Windows + 向左/向右 - 箭头键

I want to disable all of them.我想禁用所有这些。

This can disable a maximize button on the title bar.这可以禁用标题栏上的最大化按钮。

HandleRef hWnd = new HandleRef(null, GetActiveWindow());
long style = GetWindowLong(hWnd, GWL_STYLE);
style &= ~WS_MAXIMIZEBOX;
SetWindowLong(hWnd, GWL_STYLE, style);

And this can disable Windows + Up-Arrow key.这可以禁用 Windows + 向上箭头键。

private static IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
{
    switch (msg)
    {
        case WM_SYSCOMMAND:
            if (wParam.ToInt32() == SC_MAXIMIZE) {
                return IntPtr.Zero;
            }
            break;
    }

    return CallWindowProc(oldWndProcPtr, hWnd, msg, wParam, lParam);
}

But the other operations still work.但其他操作仍然有效。
How can I disable the other operations?如何禁用其他操作?

private static IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
{
    switch (msg)
    {
        case WM_SYSCOMMAND:
            if (wParam.ToInt32() == SC_MAXIMIZE) {
                return IntPtr.Zero;
            }
            break;
        // BY PASS *** Alt + Enter ***
        case WM_KEYDOWN:
        case WM_SYSKEYDOWN:
            if (wParam == VK_RETURN)
                if ((HIWORD(lParam) & KF_ALTDOWN))
                    return 0;
            break;  
    }

    return CallWindowProc(oldWndProcPtr, hWnd, msg, wParam, lParam);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM