如何防止窗口临时调整大小?

发布于 2024-08-13 21:24:02 字数 142 浏览 5 评论 0原文

我有一个可以调整大小的窗口,但在某些情况下,由于应用程序状态而无法调整大小。有没有办法暂时防止调整窗口大小?

我想通过用户可用的一切方式禁用调整大小,其中包括窗口菜单、通过鼠标拖动边缘、由操作系统执行的用户启动的窗口平铺 - 也许还有其他一些我不知道的?

I have a window which can be resized, but there are some situations when resizing is not possible because of the application state. Is there a way to prevent resizing the window temporarily?

I want to disable resizing by all means available to the users, which include window menu, dragging edges by mouse, user initiated window tiling performed by OS - and perhaps some other I am not aware of?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

假情假意假温柔 2024-08-20 21:24:02

要保留窗口边框的外观并仍然防止重新调整大小(和光标更改),请捕获 WM_NCHITTEST,将其传递给 DefWindowProc,如果返回的代码是大小常量之一,请更改实际返回值到其他东西,例如 HTCLIENT

To retain the look of the window border and still prevent re-size (and cursor change), catch WM_NCHITTEST, pass it to DefWindowProc, if the returned code is one of the size constants, change the real return to something else, HTCLIENT for example

梦幻的味道 2024-08-20 21:24:02

一种方法是使用 GetWindowLong()使用 GWL_STYLE 标志来获取窗口样式和
重置/删除您需要的任何样式,即 WS_THICKFRAME 样式,以便窗口无法调整大小。

您可以使用 SetWindowLong 应用新样式。

One way is to use GetWindowLong() with GWL_STYLE flag to get the window style and
reset/remove any styles you need, ie the WS_THICKFRAME style so that the window can't be resized.

You apply the new style with SetWindowLong.

三生池水覆流年 2024-08-20 21:24:02

另一种可能性是处理 WM_GETMINMAXINFO 消息并设置 MINMAXINFO 结构,使窗口的最小和最大大小均为当前大小。那么用户也无法调整窗口大小。

Another possibility is to handle the WM_GETMINMAXINFO message and set the MINMAXINFO struct so that both min and max size of the window is the current size. Then the user can't resize the window either.

酒浓于脸红 2024-08-20 21:24:02

窗口过程中的以下代码似乎可以处理用户拖动窗口边缘/角落的情况:

case WM_SIZING:
    RECT &rc = *(LPRECT) lParam;
    RECT windowRect;
    GetWindowRect(hwnd, &windowRect);
    rc = windowRect;
    return 0;

我还没有找到任何可以阻止系统在平铺/级联窗口时调整窗口大小的内容。我希望以下内容可以解决问题,但似乎没有:

case WM_SIZE:
   return TRUE;

我想我可以为其他情况找到类似的措施,但至少我需要知道可能导致窗口改变其大小的消息的详尽列表。

另外,虽然这确实阻止了窗口调整大小,但我宁愿阻止用户启动调整大小,也不愿明显让他调整大小然后拒绝这样做。

Following code in the window procedure seems to handle the case of user dragging the window edge/corner:

case WM_SIZING:
    RECT &rc = *(LPRECT) lParam;
    RECT windowRect;
    GetWindowRect(hwnd, &windowRect);
    rc = windowRect;
    return 0;

I did not find anything yet to prevent the system from resizing the window when tiling/cascading windows. I hoped following might do the trick, but it seems it does not:

case WM_SIZE:
   return TRUE;

I guess I can find similar measure for other cases, but at least I would need to know the exhaustive list of messages which can result in a window changing its size.

Also, while this really prevents the window from resizing, I would rather prevent the user from even initiating the resize, than apparently letting him to resize and then refusing to do so.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文