0

感谢您的回复,我查看了 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 *'

并且窗口仍然可以自由调整大小。

4

1 回答 1

3

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

编辑:

您必须在附加到窗口的消息处理过程中处理此消息。(参见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;
于 2013-07-14T17:52:12.377 回答