给你两段delphi程序,你自己翻译成C++ Builder的吧:
方法1:
Unit Unit1;
InterfaceUses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;Type
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TmouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TshiftState; X,
Y: Integer);
Private
{ Private declarations }
public
{ Public declarations }
end;
var Form1: TForm1;
Ylx,yly:integer; //定义一个全局变量
Implementation
{$R *.DFM}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TmouseButton;
Shift: TShiftState; X, Y: Integer);Begin Ylx:=x; //记录鼠标原来的坐标值 Yly:=y;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TshiftState; X,
Y: Integer);
Begin
If ssleft in shift then begin //按下鼠标左键拖动form1
form1.left:=form1.left+x-ylx;
form1.top:=form1.top+y-yly;
end;
end;
end.
方法2:
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); private { Private declarations }
public
procedure wm(var msg:Twmnchittest);message wm_nchittest;
end;
procedure TForm1.wm_nchittest(var msg: Twmnchittest);
begin
inherited;
msg.Result:=htcaption;
end;