[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 657
  • Last Modified:

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.
0
krupini
Asked:
krupini
  • 3
  • 2
1 Solution
 
jkrCommented:
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;
0
 
jkrCommented:
Sorry, that line should end with a ';':

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

return DefWindowProc(hWnd, msg, (WPARAM) fwSizeType, MAKELPARAM(nHeight,nWidth));
0
 
rcarlanCommented:
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
0
 
rcarlanCommented:
If you want to limit the window size to between a minimum size and a maximum size, set the ptMinTrackSize and ptMaxTrackSize to the desired width/height and return 0.

Radu
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now