Set min window size

Started by
6 comments, last by GameDev.net 18 years, 6 months ago
Hi, I need to set minimal window size. I could find only one way of doing it: checking window size when a WM_SIZING message is recieved. I'm interested in is there another way to set the restrictions (for ex., using other functions)?
Advertisement
I thinks its better to do it in WM_WINDOWPOSCHANGING! Much, muches better, because sometimes windows don't receives WM_SIZING messages at all, if WM_ERASEBKGND returns 0, or something like that.
Thanks.
But I've got another problem now. How to block the resizing?
I've tried:

case WM_WINDOWPOSCHANGING:{RECT wndRect;GetWindowRect(hwnd,&wndRect);if ((wndRect.right-wndRect.left)<WND_W || (wndRect.bottom-wndRect.top)<WND_H){SetWindowPos(hwnd,HWND_TOP,wndRect.left,wndRect.top,WND_W,WND_H,SWP_NOMOVE);	}return 0;} break;

but it doesn't work.
Google WM_WINDOWPOSCHANGING, and click on the msdn link. As I am feeling kind today, (see the end for a little more clue)

The WM_WINDOWPOSCHANGING message is sent to a window whose size, position, or place in the Z order is about to change as a result of a call to the SetWindowPos function or another window-management function.

WM_WINDOWPOSCHANGING
lpwp = (LPWINDOWPOS) lParam; // points to size and position data


Parameters

lpwp

Value of lParam. Points to a WINDOWPOS structure that contains information about the window's new size and position.

Return Values

If an application processes this message, it should return zero.

Default Action

For a window with the WS_OVERLAPPED or WS_THICKFRAME style, the DefWindowProc function sends the WM_GETMINMAXINFO message to the window. This is done to validate the new size and position of the window and to enforce the CS_BYTEALIGNCLIENT and CS_BYTEALIGNWINDOW client styles. By not passing the WM_WINDOWPOSCHANGING message to the DefWindowProc function, an application can override these defaults.

Remarks

While this message is being processed, modifying any of the values in WINDOWPOS affects the window's new size, position, or place in the Z order. An application can prevent changes to the window by setting or clearing the appropriate bits in the flags member of WINDOWPOS.

See Also

DefWindowProc, EndDeferWindowPos, SetWindowPos, WINDOWPOS, WM_GETMINMAXINFO, WM_MOVE, WM_SIZE, WM_WINDOWPOSCHANGED


This means that you have to play with the lParam message parameter Windows sent you. See if you can figure it out.
The only viable way (without flickering) to do this is to process WM_GETMINMAXINFO. This messages gets sent in advance to every WM_SIZE or similar message. You can fill in structs for min and max size which Windows will respect.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Quote:Original post by Endurion
The only viable way (without flickering) to do this is to process WM_GETMINMAXINFO...


Not true. You can do as hinted at in my last message, and if you set WM_ERASEBKGND handler to return 0, you can entirely eliminate flicker.

- The flicker-free god
Quote:Original post by Anonymous Poster
Google WM_WINDOWPOSCHANGING, and click on the msdn link


Yes, I visited msdn, but I missed that text block about lParam :( ...

So it works now. Though from time to time when resizing window its size becomes smaller than needed and if I press Maximize button after that, the window doesn't maximize, and only moves to (0,0) corner. What is wrong?

Quote:Original post by Anonymous Poster
if you set WM_ERASEBKGND handler to return 0, you can entirely eliminate flicker.


Couldn't you describe it in more details? I can't figure it out.
Quote:...So it works now. Though from time to time when resizing window its size becomes smaller than needed and if I press Maximize button after that, the window doesn't maximize, and only moves to (0,0) corner. What is wrong?


Don't know. You are doing something strange in your handler. If you post the minimal code, maybe someone here can help you further.

Quote:
Quote:Original post by Anonymous Poster
if you set WM_ERASEBKGND handler to return 0, you can entirely eliminate flicker.


Couldn't you describe it in more details? I can't figure it out.


You can download a full code example, and read about the technique in the article that describes what I did to accomplish that and a couple other things: http://www.codeproject.com/library/DWinLib.asp. Maybe you can see what you did wrong in the above by looking at how the code in there works. The StupidSquares example has code to minimize, maximize, and save / restore the state upon closing / opening, so that might be helpful to you. You will have to dig a little, but it should be a very learning experience.

Good luck, and have fun!

David

This topic is closed to new replies.

Advertisement