简体   繁体   English

阻止窗口最大化功能? (完全)

[英]Block window maximize functionality? (Completely)

I am trying to create a window with behavior similar to cmd.exe , specifically whereby I don't want to support maximizing the window, since I only show fully visible lines of text (vertically). 我正在尝试创建一个行为类似于cmd.exe的窗口,特别是在此我不希望支持最大化窗口,因为我仅显示(垂直)完全可见的文本行。 I have come up with two solutions so far: 到目前为止,我已经提出了两种解决方案:

Solution 1: 解决方案1:

case WM_SYSCOMMAND:
            if (wParam == SC_MAXIMIZE) {
                return 0;
            }
            return DefWindowProc(hWnd, message, wParam, lParam);
            break;

Solution 2: 解决方案2:

case WM_SIZE:
        if (wParam == SIZE_MAXIMIZED) {
            SendMessage(hWnd, WM_SYSCOMMAND, SC_RESTORE, 0);
            return 0;
        }
        break;

Unfortunately, the former is only effective if the user explicitly clicks the maximize button in the title bar, or in a context menu. 不幸的是,前者仅在用户明确单击标题栏中或上下文菜单中的最大化按钮时才有效。 It won't block it if the user simply double clicks the title bar for example. 例如,如果用户仅双击标题栏,它就不会阻止它。

The problem with the latter solution, for me, is that it causes scrollbars to disappear until you resize the window manually (by dragging the sides). 对我而言,后一种解决方案的问题在于,它会导致滚动条消失,直到您手动调整窗口大小(通过拖动侧面)为止。 Also, you can sometimes see the window flash before the window size is restored (I did try disabling redrawing before sending WM_SYSCOMMAND / SC_RESTORE , but unfortunately it did not help much). 另外,有时您会在恢复窗口大小之前看到窗口闪烁(我确实尝试在发送WM_SYSCOMMAND / SC_RESTORE之前禁用重绘,但不幸的是,它没有太大帮助)。

Is there a better solution that I'm missing? 有没有更好的解决方案?

case WM_SYSCOMMAND:
    UINT SysCommandCode = wParam & 0xFFF0;
    if (SysCommandCode == SC_MAXIMIZE) {
        return 0;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
    break;

Also it is recommended to remove WS_MAXIMIZEBOX from the windows style (when creating). 另外,建议从Windows样式中删除WS_MAXIMIZEBOX(创建时)。

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

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