1

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.

Jimmay
  • 959
  • 3
  • 13
  • 27
  • Please avoid creating duplicate questions by first looking for a simliar question using both the search function for stackoverflow and google. I typed your question into google and this was the FIRST search result: http://stackoverflow.com/questions/5794630/setting-a-windows-minimum-and-maximum-size-using-winapi – moonbeamer2234 Jul 14 '13 at 18:14
  • That answer does not go into nearly enough detail. – Jimmay Jul 14 '13 at 18:17
  • @Jimmay I'm not sure if I got your Intention right: You try to influence min/max from outside an application? – junix Jul 14 '13 at 18:33
  • No, it's my own application. – Jimmay Jul 14 '13 at 18:48
  • Uhm... As the name suggests `WM_GETMINMAXINFO` returns the min and max size the window is willing to be. You seem to call this function to *set* the size. That's wrong. Instead handle the message (using whatever mechanism the framework you use provides) and return the mom and max size. – Nik Bougalis Jul 14 '13 at 19:01
  • I don't understand what you mean by framework. Is that relevant? Can't I just do something like SendMessage(hwnd, WM_SETMINMAXINFO, NULL, &info); – Jimmay Jul 14 '13 at 19:17
  • So can no one post a working example of how to set the min and max size of the window? – Jimmay Jul 14 '13 at 19:49
  • @Jimmay As you might have found yourself, there is no such message as WM_SETMINMAXINFO defined in the Windows API. As this is an undefined message, it's pointless to send this. I added an example to my answer, where I explain how an application can tell Windows about the limits for resizing it's windows. – junix Jul 19 '13 at 11:29

1 Answers1

4

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;
junix
  • 3,161
  • 13
  • 27
  • I am still really confused as to how to do this. Please can you post a full example. – Jimmay Jul 18 '13 at 17:57
  • @Jimmay I tried to improve my answer, taking into account, that you replied to my comment above that you are trying to set min/max for your own application. – junix Jul 19 '13 at 11:26