delphi 中按钮拖动
想实现按钮拖动的功能,在OnMouseMove中ReleaseCapture;
SendMessage(APanel.Handle,WM_NCLBUTTONDOWN , HTCaption, 0);
然后ONMOUSEUP事件就失效。我还想要ONMOUSEUP事件,这个怎么办啊???
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
procedure FormCreate(Sender: TObject);
private
FOldWndProc: TWndMethod;
public
procedure NewWndProc(var m: TMessage);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FOldWndProc := btn1.WindowProc;
btn1.WindowProc := NewWndProc;
end;
procedure TForm1.NewWndProc(var m: TMessage);
begin
FOldWndProc(m);
if (m.Msg = WM_MOUSEMOVE) and (m.WParam = MK_LBUTTON) then
begin
ReleaseCapture;
Perform(WM_NCLBUTTONDOWN, HTCAPTION, m.LParam);
// 在这里做 mouseup 事件中要做的事
ShowMessage('这里做 mouseup 事件中要做的事');
end;
end;
end.