Jimmay
Jimmay

Reputation: 1009

How to set minimum and maxiumum window size

Thanks for your response, I looked into SendMessage but got a little stuck, I am now using this code:

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;

Now I have these warnings:

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 *'

And the window is still freely re sizable.

Upvotes: 1

Views: 2881

Answers (1)

junix
junix

Reputation: 3221

WM_GETMINMAXINFO is not a function, it's just an identifier of a message you can send to a window. You can send these messages using SendMessage or you have to handle it in your WindowProc, depending of what you want to achieve.

EDIT:

You have to handle this message in your message handling procedure you attached to the window. (see WindowProc in the MSDN) As the documentation of WM_GETMINMAXINFO explains, the message is sent to the window by the OS, everytime is about to resize to query the limits of your windows's size.

What you can do is, to add following code to your window procedure:

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;

Upvotes: 5

Related Questions