• 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?
0
batboy2_
Asked:
batboy2_
1 Solution
 
DanRollinsCommented:
Here's 50 points worth of answer:
Imagine that you want to enforce x=2y... Add this to you WindowProc:

     case WM_WINDOWPOSCHANGING: {
          WINDOWPOS* rWP= (WINDOWPOS*)lParam;
          rWP->cx= (rWP->cy * 2);
     }
     break;
=-=-=-=-=-=-=-=-=-
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
0
 
batboy2_Author Commented:
Thank you. After a little tweaking that solved the problem.
0

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