2

If I double click top border of a window it will resize vertically from top to the bottom of the desktop, but retain its width.

How do I do it in code?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Tracer
  • 2,544
  • 2
  • 23
  • 58
  • I retagged as winapi. Good question. – David Heffernan Dec 11 '15 at 19:10
  • There is no dedicated API exposed to invoke the Aero snap feature (see [Programatically invoke Snap/Aero maximize](http://stackoverflow.com/q/25833996/1889329)). It boils down to calling [SetWindowPos](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633545.aspx) with appropriate values. Unfortunately, this only approximates the effect. The window will not restore its lower edge when you start to drag the top border away from the edge. @MartynA: You clicked the title bar, not the top border then. The cursor changes its shape when you are over to border rather than the title bar. – IInspectable Dec 11 '15 at 19:15
  • Should'nt there be a way to send message (SendMessage) to resize a window in that way? – Tracer Dec 11 '15 at 19:17
  • @IInspectable: "cursor changes its shape when you are over to border" True, but dbl-clicking while the vertical sizing arrows are displayed does nothing on my machine. – MartynA Dec 11 '15 at 19:20
  • You may try to SendInput a WinKey+Shift+Up though it's not entirely trivial due to WinKey usage. – dxiv Dec 11 '15 at 19:29
  • @Tracer No, there is no such API – David Heffernan Dec 11 '15 at 20:09

1 Answers1

0

Probably by just this code:

with Screen.MonitorFromWindow(Handle).WorkareaRect do
  SetBounds(Self.Left, Top, Self.Width, Height);

And the following alternative adds an animation:

Hide;
with Screen.MonitorFromWindow(Handle).WorkareaRect do
  SetBounds(Self.Left, Top, Self.Width, Height);
AnimateWindow(Handle, 200, AW_ACTIVATE or AW_VER_POSITIVE);

To be able to restore to the previous size, I thought SetWindowPlacement could be used, but I cannot make it work though.

NGLN
  • 43,011
  • 8
  • 105
  • 200