Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force a window to maintain a certain width/height ratio when resized

Tags:

c++

winapi

I want my window to always maintain a certain ratio of let's say 1.33333333. So, if the window is width = 800, height = 600 and the user changes the width to 600, I want to change the height to 450 automatically.

I'm already intercepting WM_SIZE but I don't know if it's enough; also I don't know how to change the width or height to maintain my ratio.

like image 949
woor Avatar asked Mar 15 '10 16:03

woor


2 Answers

WM_SIZING is sent to the window while the user is resizing the window.

Rather handle WM_WINDOWPOSCHANGING - this is sent by the internal SetWindowPos function when code (or the user) changes the window size and will ensure that even tile & cascade operations obey your sizing policy.

like image 115
Chris Becke Avatar answered Nov 15 '22 00:11

Chris Becke


See WM_SIZING: http://msdn.microsoft.com/en-us/library/ms632647.aspx

Processing this message allows you to change resulting window size.

like image 22
Janusz Lenar Avatar answered Nov 14 '22 23:11

Janusz Lenar