简体   繁体   English

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

[英]How to prevent window resizing temporarily?

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? 我想通过用户可用的一切手段禁用调整大小,包括窗口菜单,鼠标拖动边缘,操作系统执行的用户启动的窗口平铺 - 以及其他一些我不知道的事情?

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

One way is to use GetWindowLong() with GWL_STYLE flag to get the window style and 一种方法是使用带有GWL_STYLE标志的GetWindowLong()来获取窗口样式和
reset/remove any styles you need, ie the WS_THICKFRAME style so that the window can't be resized. 重置/删除所需的任何样式 ,即WS_THICKFRAME样式,以便无法调整窗口大小。

You apply the new style with SetWindowLong. 您使用SetWindowLong应用新样式

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. 另一种可能性是处理WM_GETMINMAXINFO消息并设置MINMAXINFO结构,以使窗口的最小和最大大小都是当前大小。 Then the user can't resize the window either. 然后用户也无法调整窗口大小。

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. 此外,虽然这确实阻止了窗口调整大小,但我宁愿阻止用户甚至启动调整大小,而不是显然让他调整大小然后拒绝这样做。

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

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