# Is there a way to set a minimum window size??

This topic is 5060 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all.. I'm just wondering if there is a way set a minimum window size in VC++. I want to be able to resize a window but for it to stop when it gets to a certain size (maybe 80x80) so you can't reduce it anymore. The reason I want to add this feature to my application is so that you can't reduce the window size to the point where the applications menu decides to split itself. I predict the solution is probably really simple but we'll see. :) Cheers, Steve B

##### Share on other sites
I'm not sure if there's a particularly neat official way, but you can always intercept the WM_SIZING message, and limit it that way (just check the new size, and it it's too small, expand it to your minimum size).

John B

##### Share on other sites
WM_GETMINMAXINFO is what you're looking for.

Specifically, you want to set the ptMinTrackSize member of the MINMAXINFO structure to your minimum size.

##### Share on other sites
Cool

Thanks for the info saladyears. Seems like that's what I've been looking for. :)

Cheers,
Steve-B

##### Share on other sites
Quote:
 Original post by saladyearsWM_GETMINMAXINFO is what you're looking for.Specifically, you want to set the ptMinTrackSize member of the MINMAXINFO structure to your minimum size.

Hi

Thanks for your help with this problem. I've given it a try but clearly I'm not doing something right. Maybe I'm just not totally clued up on how the window messaging system works. First I tried to somehow read (in the WM_GETMINMAXINFO message) the lParam but couldn't really work out how to read/store the pointer to the MINMAXINFO structure.

So what I thought was that I could make a global handle to the MINMAXINFO structure like I do when I create my global handle hWnd. I then noticed the values in the structure were all zero which I thought was a bit strange. So anyway I altered the ptMinTrackSize.x and ptMinTrackSize.y values (inside WM_GETMINMAXINFO) to 100 and 100 to see if this would limit the window sizing however this didn't work. I could still resize the window to it's default smallest point. What on earth am I doing wrong??

I think I need to actually read/store and modify the lParam value instead of a handle to the structure? Or am I maybe on the right track?? :)

Cheers,
Steve-B

##### Share on other sites
The lParam value is a pointer to the MINMAXINFO structure that you want to manipulate. You'd probably try something like this:
case WM_GETMINMAXINFO{  MINMAXINFO& MinMaxInfo = *((LPMINMAXINFO)lParam);  MinMaxInfo.ptMinTrackSize.x = WND_WIDTH_MIN;  MinMaxInfo.ptMinTrackSize.y = WND_HEIGHT_MIN;  MinMaxInfo.ptMaxTrackSize.x = WND_WIDTH_MAX;  MinMaxInfo.ptMaxTrackSize.y = WND_HEIGHT_MAX;  return 0;}

I haven't used this method myself, since I didn't realize it existed, so I don't know if it'll work. I just recently used JohnBSmall's suggestion, myself, which worked fine, so if this doesn't work, you might try that one out. It's very similar, in that you need to treat lParam as a pointer to a RECT structure.

##### Share on other sites
Hi Agony

Thanks a lot. I used a similar piece of code and it worked just great. :)

case WM_GETMINMAXINFO:{    MINMAXINFO* win_size = (MINMAXINFO*)(lParam);    win_size.ptMinTrackSize.x = DEF_WIN_X;    win_size.ptMinTrackSize.y = DEF_WIN_Y;    return(0);}break;

##### Share on other sites
Sweet. I might fix my other program to use this message instead of WM_SIZING...

(I'm guessing it's just a typo that you used "win_size." instead of "win_size->". I'd have a hard time seeing it actually working, otherwise, though, and you said it worked. Just making sure.)

##### Share on other sites
Quote:
 Original post by Agony(I'm guessing it's just a typo that you used "win_size." instead of "win_size->". I'd have a hard time seeing it actually working, otherwise, though, and you said it worked. Just making sure.)

Hi Agony

Well I've just knocked that piece of code up from memory (I'll check tonight) but I'm pretty sure that is what it looks like. It definitely doesn't have the (->) pointer thingy. :)

I have come across a new problem though. It's a bit of an odd question but here goes...I wonder if anyone knows how to manually tell a window that it has already been restored from a maximum state (without actually clicking on the maximize button). I made it so with a button press the window is restored to it's default size. Unfortunately if you do this when the window is in a maximized state then try and resize the window it won't show the two-way arrow icon because it still thinks the window is maximized. Is there anyway around this interesting little problem? :)

Steve-B

##### Share on other sites
When you press the button, do you simply call SetWindowPos() or something similar? Try also adding a call to ShowWindow(hWnd, SW_SHOWNORMAL) right before that. That way, if it is maximized, it will restore it, [I think]. Or you might try the SW_RESTORE constant instead.

• 18
• 11
• 16
• 9
• 49
• ### Forum Statistics

• Total Topics
631396
• Total Posts
2999782
×