如何修复窗口的宽度,同时高度可调整大小? [英] How do I fix the width of a window, while the height is resizable?

查看:169
本文介绍了如何修复窗口的宽度,同时高度可调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试处理Windows消息,例如WM_SIZING,WM_SIZE等。大多数是在更改宽度或高度时与之相关或调用的消息。我试图使用MoveWindow和SetWindowPos设置值,但没有发生任何事情,而不是Windows闪烁并返回默认值。我如何强制修复宽度或高度,但不是两个都是我的挑战。



我尝试过:



我试过这个



I am trying to handle a windows message, such as WM_SIZING, WM_SIZE, etc. Mostly those related to or is called when the width or height is changed. I have tried to set the value using MoveWindow and SetWindowPos but nothing is happening, instead of the windows flickers and return to default. How do I force the width or height to be fixed but not both is my challenge.

What I have tried:

I tried this

((MINMAXINFO*)message.lParam())->ptMinTrackSize.x = m_fixedSize.width();




((MINMAXINFO*)message.lParam())->ptMinTrackSize.y = m_fixedSize.height();

推荐答案

最简单的方法是处理WM_SIZE消息,该消息在窗口收到新大小后调用,但在它重新粉刷之前。您只需将新宽度与所需宽度进行比较即可。如果它是相同的,什么都不做。如果它不同,请使用新的高度(在WM_SIZE消息中收到)和所需的宽度调用SetWindowPos()API。



例如,以下内容使用消息< windowsx.h> 中的破解程序解析消息:



The easiest way is to handle the WM_SIZE message, which is called after the window receives its new size, but before it is repainted. You simply compare the new width to your desired width. If it is identical, do nothing. If it differs, call the SetWindowPos() API with the new height (received in the WM_SIZE message) and your desired width.

For example, the following uses the Message Crackers in <windowsx.h> to parse the message:

static void onSize(HWND hwnd, UINT /*state*/, int cx, int cy)
{
    /* code to prevent the window from exceeding a "full text page" */
    BOOL resize = FALSE;

    if (cx > wintext_max_width)
    {
        resize = TRUE;
        cx = wintext_max_width;
    }
    if (cy > wintext_max_height)
    {
        resize = TRUE;
        cy = wintext_max_height;
    }
    if (resize)
        SetWindowPos(hwnd,
                     GetNextWindow(hwnd, GW_HWNDPREV),
                     0, 0,
                     cx, cy,
                     SWP_NOMOVE);
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        /* other messages go here */
        case WM_SIZE:
            return HANDLE_WM_SIZE(hwnd, wParam, lParam, onSize);

        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
}


这篇关于如何修复窗口的宽度,同时高度可调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆