Delphi window losing focus after custom drag

笑着哭i 提交于 2019-12-12 21:27:08

问题


I've got this code that moves my Main Window around when I drag around MyThingThatDragsIt

procedure TMainForm.ApplicationMessage(var Msg: TMsg; var Handled: Boolean);
var
  ScreenPt : TPoint;
  DragControl : TControl;

begin
  inherited;
  if Msg.message = WM_LBUTTONDOWN then
  begin

    ScreenPt := ScreenToClient(Msg.pt);
    DragControl := FindDragTarget(Msg.pt , false);
    if Assigned(DragControl) and
      ((DragControl = MyThingThatDragsIt)
      ) then
    begin
      ReleaseCapture;
      self.Perform(WM_SYSCOMMAND, SC_MOVE or $0002, 0 );
    end;
  end
end;

That works OK, but when I let go, my program has lost it's focus and I've got to click once on the form just to click on any other buttons.

Any idea what is wrong here? I followed steps from this question


回答1:


Tell the VCL that you've taken care of the message:

  ...
  Perform(WM_SYSCOMMAND, SC_MOVE or $0002, 0 );
  Handled := True;
  ...


来源:https://stackoverflow.com/questions/15821670/delphi-window-losing-focus-after-custom-drag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!