如何防止窗口临时调整大小?
我有一个可以调整大小的窗口,但在某些情况下,由于应用程序状态而无法调整大小。有没有办法暂时防止调整窗口大小?
我想通过用户可用的一切方式禁用调整大小,其中包括窗口菜单、通过鼠标拖动边缘、由操作系统执行的用户启动的窗口平铺 - 也许还有其他一些我不知道的?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要保留窗口边框的外观并仍然防止重新调整大小(和光标更改),请捕获 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一种方法是使用 GetWindowLong()使用
GWL_STYLE
标志来获取窗口样式和重置/删除您需要的任何样式,即
WS_THICKFRAME
样式,以便窗口无法调整大小。您可以使用 SetWindowLong 应用新样式。
One way is to use GetWindowLong() with
GWL_STYLE
flag to get the window style andreset/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.
另一种可能性是处理 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.
窗口过程中的以下代码似乎可以处理用户拖动窗口边缘/角落的情况:
我还没有找到任何可以阻止系统在平铺/级联窗口时调整窗口大小的内容。我希望以下内容可以解决问题,但似乎没有:
我想我可以为其他情况找到类似的措施,但至少我需要知道可能导致窗口改变其大小的消息的详尽列表。
另外,虽然这确实阻止了窗口调整大小,但我宁愿阻止用户启动调整大小,也不愿明显让他调整大小然后拒绝这样做。
Following code in the window procedure seems to handle the case of user dragging the window edge/corner:
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:
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.