Link to home
Start Free TrialLog in
Avatar of krupini
krupini

asked on

How to set a minimum and maximum size of a window in Win32 API?

How do you set a minimum and maximum size of a window (form) in Win32 API? So far I know that the window WindowProc() method should be listening for WM_GETMINMAXINFO message .. after that, I am lost. Please help.



Thanks.
Avatar of jkr
jkr
Flag of Germany image

You should do that when handling WM_SIZE, e.g. like

case WM_SIZE:

#define HEIGHT_MAX 200
#define WIDTH_MAX 200

WORD fwSizeType = wParam;      // resizing flag
int nWidth = LOWORD(lParam);  // width of client area
int nHeight = HIWORD(lParam); // height of client area

if ( nHeight > HEIGHT_MAX) nHeight = HEIGHT_MAX;
if ( nWidth > WIDTH_MAX) nWidth = WIDTH_MAX;

return DefWindowProc(hWnd, msg, (WPARM) fwSizeType, MAKELPARAM(nHeight,nWidth)):

break;
Sorry, that line should end with a ';':

return DefWindowProc(hWnd, msg, (WPARM) fwSizeType, MAKELPARAM(nHeight,nWidth));
...and it actually should read

return DefWindowProc(hWnd, msg, (WPARAM) fwSizeType, MAKELPARAM(nHeight,nWidth));
Avatar of rcarlan
rcarlan

Respond to this window message: WM_GETMINMAXINFO (lParam points to a MINMAXINFO structure).

Windows sends this message to a window whose size or position is about to change. For example, the message is sent when the user clicks Move or Size from the window menu or clicks the sizing border or title bar; the message is also sent when an application calls SetWindowPos to move or size the window.

Radu
ASKER CERTIFIED SOLUTION
Avatar of rcarlan
rcarlan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial