Sign in to follow this  
Steve-B

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

Recommended Posts

Steve-B    150
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 this post


Link to post
Share on other sites
Steve-B    150
Quote:
Original post by saladyears
WM_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 this post


Link to post
Share on other sites
Agony    3452
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 this post


Link to post
Share on other sites
Steve-B    150
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 this post


Link to post
Share on other sites
Agony    3452
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 this post


Link to post
Share on other sites
Steve-B    150
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 this post


Link to post
Share on other sites
Agony    3452
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.

Share this post


Link to post
Share on other sites
Steve-B    150
I basically just call a function I wrote called RestoreWindowSize() which alters the window x,y,width and height variables back to their original values and then it calls the MoveWindow() funtion to reposition the window. I tried using the SendMessage() function to send a WM_SIZE message with the SIZE_RESTORED option in the hope that the window would think it had been restored but that didn't work. Eek! lol. :P

Steve-B

Share this post


Link to post
Share on other sites
Steve-B    150
Quote:
Original post by Agony
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.

Yes, I'll give this a try and see if it works. Hopefully it will. :)

Cheers,
Steve-B

Share this post


Link to post
Share on other sites
Steve-B    150
Hi Agony

SW_SHOWNORMAL didn't work too well as it only restores the image to it's last position. I want to set it at a pre-defined position and I think I can do this using the ShowWindow(hWnd, SW_SHOWDEFAULT) option. I'll have to investigate this further though. :)

Also you were right about the code I posted a few days ago. I did use the pointer dereference arrow (->) to alter the MINMAXINFO structure members. I checked my code and realised, so I've posted the code straight from my program. I think when I wrote that earlier post I must have been thinking I was accessing a normal structure and not a structure pointer. Either that or I was away with the fairies. lol.


// Store window MINMAXINFO structure pointer
MINMAXINFO* hMinMax = (MINMAXINFO*)(lParam);
hMinMax->ptMinTrackSize.x = (WINDOW_X_MIN + winfo.borderWidth);
hMinMax->ptMinTrackSize.y = (WINDOW_Y_MIN + winfo.borderHeight);



Cheers,
Steve

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this