如何设置最小和最大窗口大小

时间:2013-07-14 17:49:21

标签: c windows

感谢您的回复,我查看了SendMessage但有点卡住,我现在正在使用此代码:

HWND hwnd = GetForegroundWindow();
MINMAXINFO info;
POINT minSize = {500, 500}, maxSize = {600, 600};
SendMessage(hwnd, WM_GETMINMAXINFO, NULL, &info); //WM_GETMINMAXINFO(NULL, &info);
info.ptMinTrackSize = minSize;
info.ptMaxTrackSize = maxSize;

现在我有这些警告:

init.c:49:3: warning: passing argument 3 of 'SendMessageA' makes integer from po
inter without a cast [enabled by default]
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winuser.h:4001:27: not
e: expected 'WPARAM' but argument is of type 'void *'
init.c:49:3: warning: passing argument 4 of 'SendMessageA' makes integer from po
inter without a cast [enabled by default]
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winuser.h:4001:27: not
e: expected 'LPARAM' but argument is of type 'struct MINMAXINFO *'

窗户仍可自由调整大小。

1 个答案:

答案 0 :(得分:3)

WM_GETMINMAXINFO不是函数,它只是您可以发送到窗口的消息的标识符。您可以使用SendMessage发送这些消息,或者您必须在WindowProc中处理这些消息,具体取决于您希望实现的目标。

修改

您必须在附加到窗口的message handling procedure处理此消息。 (请参阅MSDN中的WindowProc)正如WM_GETMINMAXINFO的文档所解释的那样,操作系统会将消息发送到窗口,每次都要调整大小以查询窗口大小的限制。

您可以做的是,将以下代码添加到您的窗口过程中:

LRESULT result = -1;

/* ... some code ... */

switch (uMsg)
{
    /* Some other Messages handled here... */

    case WM_GETMINMAXINFO:
    {
        HINMAXINFO *minmax = (MINMAXINFO *)lParam;
        minmax->ptMinTrackSize.x = 500;
        minmax->ptMinTrackSize.y = 500;
        minmax->ptMaxTrackSize.x = 600;
        minmax->ptMaxTrackSize.y = 600;
        result = 0;
        break;
    }

}

return result;