【发布时间】:2014-05-13 22:23:21
【问题描述】:
我正在编写一个 MFC 应用程序,它需要允许垂直调整窗口大小并防止水平调整大小。最简单的方法是什么?
【问题讨论】:
我正在编写一个 MFC 应用程序,它需要允许垂直调整窗口大小并防止水平调整大小。最简单的方法是什么?
【问题讨论】:
您想捕捉WM_SIZING 和WM_GETMINMAXINFO 以强制使用适当的宽度,(WM_NCHITTEST 过滤掉任何导致用户尝试更改宽度的响应(可能不需要...))。
如果没有多显示器设置,单独使用 WM_GETMINMAXINFO 就足够了。
还可以查看GetSystemMenu(),可能会定制您的系统菜单。
顺便说一句:这个答案不是 MFC 特定的。
【讨论】:
WM_SIZING 和 WM_GETMINMAXINFO 以防止在一个方向或另一个方向上调整大小?如果我没记错的话,这可以通过只处理WM_GETMINMAXINFO 来优雅地完成。 (在这种情况下你为什么需要GetSystemMenu?)
For systems with multiple monitors, the ptMaxSize and ptMaxPosition members describe the maximized size and position of the window on the primary monitor, even if the window ultimately maximizes onto a secondary monitor. In that case, the window manager adjusts these values to compensate for differences between the primary monitor and the monitor that displays the window. Thus, if the user leaves ptMaxSize untouched, a window on a monitor larger than the primary monitor maximizes to the size of the larger monitor. 那么,你有多个显示器吗?
WM_WINDOWPOSCHANGING 并将WINDOWPOS.cx 设置为窗口的恒定宽度。这种方法的一个缺点是,当用户尝试从左侧调整大小时,窗口看起来就像被拖到左侧一样。