Recent

Author Topic: How to detect when title bar is clicked or form is dragged?  (Read 3290 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1013
    • HowTos Considered Harmful?
How to detect when title bar is clicked or form is dragged?
« on: April 26, 2015, 04:22:57 pm »
How do you detect when then title bar is clicked or the form is dragged?

There don't seem to be any events for handling those.
Lazarus 3.0/FPC 3.2.2

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How to detect when title bar is clicked or form is dragged?
« Reply #1 on: April 26, 2015, 06:07:15 pm »
Try OnChangeBounds event.

vfclists

  • Hero Member
  • *****
  • Posts: 1013
    • HowTos Considered Harmful?
Re: How to detect when title bar is clicked or form is dragged?
« Reply #2 on: April 27, 2015, 10:37:24 am »
Try OnChangeBounds event.

How can that be exposed in code?
There is no event for it in the Object inspector.
Lazarus 3.0/FPC 3.2.2

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How to detect when title bar is clicked or form is dragged?
« Reply #3 on: April 27, 2015, 11:49:38 am »
There is no event for it in the Object inspector.

Of course there is.

Click on the form, click on Events Object Inspector's tab and doubleclick in OnChangeBounds event.

vfclists

  • Hero Member
  • *****
  • Posts: 1013
    • HowTos Considered Harmful?
Re: How to detect when title bar is clicked or form is dragged?
« Reply #4 on: April 27, 2015, 02:24:43 pm »
There is no event for it in the Object inspector.

Of course there is.

Click on the form, click on Events Object Inspector's tab and doubleclick in OnChangeBounds event.

Found it.  :)

What about the click of the titlebar? Is it detected by the form, or is it only the operating system that can detect it?
Lazarus 3.0/FPC 3.2.2

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: How to detect when title bar is clicked or form is dragged?
« Reply #5 on: April 27, 2015, 02:39:58 pm »
What about the click of the titlebar? Is it detected by the form, or is it only the operating system that can detect it?
Not too long ago this was discussed in another topic:
http://forum.lazarus.freepascal.org/index.php/topic,28060.msg174614.html#msg174614
(This is for detecting the click on the titlebar as well as the borders of a form)

This is for Windows (not sure about the other OSes):
Code: [Select]
uses windows;

var
  PrevWndProc: WNDPROC;

function WndCallback(HWnd: HWND; Msg: UINT; WParam: WParam; LParam: LParam):LRESULT; stdcall;
begin
  if Msg = WM_NCLBUTTONDOWN then //left down
  begin

  end;
  if Msg = WM_NCLBUTTONUP then //left up
  begin

  end;
  Result := CallWindowProc(PrevWndProc, HWnd, Msg, WParam, LParam);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  PrevWndProc := Windows.WNDPROC(SetWindowLongPtr(Self.Handle, GWL_WNDPROC, PtrInt(@WndCallback)));
end;         

 

TinyPortal © 2005-2018