• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • Last Modified:

Resizing a window while keeping the aspect ratio.

Using the standard windows API, how can I make a window resize with a fixed aspect ratio (for example 1.3h x h) when dragging the resize border?
1 Solution
Here's 50 points worth of answer:
Imagine that you want to enforce x=2y... Add this to you WindowProc:

          WINDOWPOS* rWP= (WINDOWPOS*)lParam;
          rWP->cx= (rWP->cy * 2);
This overrides the size settings.  You will need to add logic to make this more intelligent.  For instance, this works if you increase or decrease the height (drag the bottom), but not the width (drag the side).  You will need to decide which direction is changing (use GetWindowRect and compare to the values in the WINDOWPOS struct).  You will also need to initially create the window with a reasonably-proportioned size or when it first opens, it will change unexpectedly (in the above example the window immediately gets very wide).

-- Dan
batboy2_Author Commented:
Thank you. After a little tweaking that solved the problem.

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

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