« Blog Home

§ TWMSizing record for Delphi

One way to control custom window sizing is to use the WM_SIZING message, but Delphi doesn't give you what you need to do so.

My (old) copy of MSDN shows:

WM_SIZING
  fwSide = wParam;         // edge of window being sized
  lprc = (LPRECT) lParam;  // screen coordinates of drag rectangle

which is identical to WM_MOVING.  Actually, the MSDN pages for WM_MOVING and WM_SIZING are nearly identical.  In fact, WM_MOVING uses the constants for WM_SIZING, e.g. WMSZ_BOTTOMLEFT.  I can't think why; I never seen a Windows window movable by anything but the titlebar.  Intrestingly, the Windows.pas unit has the WMSZ_BOTTOMLEFT et. al. constants, although I don't see them used elsewhere in the source.


TWMMoving from Messages.pas:

TWMMoving = packed record
  Msg: Cardinal;
  Edge: Integer;
  DragRect: PRect;
end;

which has no result.  I mean, MSDN says, "An application should return TRUE if it processes this message."  (That goes for either WM_MOVING or WM_SIZING.)


So here's TWMSizing:

type
  TWMSizing = packed record
    Msg: Cardinal;
    Edge: Integer;
    DragRect: PRect;
    Result: Longint;
  end;

This lets you do something like:

procedure WMSizing(var Message: TWMSizing); message WM_SIZING;
...
procedure TForm2.WMSizing(var Message: TWMSizing);
begin
  case Message.Edge of
    WMSZ_BOTTOMRIGHT: begin
      Message.DragRect.Bottom := Top + Height;  //can make it wider but not taller
      Message.Result := 1;  //return TRUE
    end;
    WMSZ_BOTTOMLEFT: begin
      Message.DragRect.Left := Left;  //can make it taller but not wider
      Message.Result := 1;  //return TRUE
    end;
  end;
end;

last edited on May 7th, 2010 at 6:38 PM

Comments

No Comments Here. Add yours below!

Add your comment

Name:
Email: (Will not be displayed - Privacy policy)
Website:
Comments:
  random image I can't read it!
Give me a different one!
Verify Post: Input the text from the image above to verify this post (helps prevent spam)
 

« Blog Home


So all he had to do was learn some Norse magic.  Free Loki.  Find Liz.  Stop Ragnarok.  Help Sygin get her revenge on the lords of the Æsir.  Defeat the Krim, and get home.
Easy, really.
Jerry, Pyramid Power, Eric Flint & Dave Freer