求教一个拖动的问题,需要API高手相助(50分)

  • 主题发起人 主题发起人 cyf_00002
  • 开始时间 开始时间
C

cyf_00002

Unregistered / Unconfirmed
GUEST, unregistred user!
我想实现一个拖动,拖动时的状态和设计时一样,以前用PICTURE来代替边框,<br>现在求教高质量的方法,望各位大哥不吝赐教!
 
想拖动什么?
 
拖运一个Edit,其它的一样:<br>procedure TForm1.Edit1MouseDown(Sender: TObject; Button: TMouseButton;<br>&nbsp; Shift: TShiftState; X, Y: Integer);<br>const<br>&nbsp; SC_DRAGMOVE = SC_MOVE + 2;<br>begin<br>&nbsp; ReleaseCapture;<br>&nbsp; PostMessage(Edit1.Handle, WM_SYSCOMMAND, SC_DRAGMOVE, 0);<br>end;<br>
 
这样更牛!<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, AppEvnts, ExtCtrls, Buttons;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; ApplicationEvents1: TApplicationEvents;<br>&nbsp; &nbsp; BitBtn1: TBitBtn;<br>&nbsp; &nbsp; ListBox1: TListBox;<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; GroupBox1: TGroupBox;<br>&nbsp; &nbsp; Panel1: TPanel;<br>&nbsp; &nbsp; procedure ApplicationEvents1Message(var Msg: tagMSG;<br>&nbsp; &nbsp; &nbsp; var Handled: Boolean);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;<br>&nbsp; var Handled: Boolean);<br>const<br>&nbsp; SC_DRAGMOVE = SC_MOVE + 2;<br>begin<br>&nbsp; if msg.message = wm_Lbuttondown then<br>&nbsp; begin<br>&nbsp; &nbsp; Handled := true;<br>&nbsp; &nbsp; ReleaseCapture;<br>&nbsp; &nbsp; PostMessage( msg.hwnd, WM_SYSCOMMAND, SC_DRAGMOVE, 0);<br>&nbsp; end;<br>end;<br><br>end.<br>
 
两位大哥真牛<br>I佩服
 
To fssky:<br>&nbsp;为什么不能 直接用SC_MOVE?<br>&nbsp; PostMessage(Edit1.Handle, WM_SYSCOMMAND, SC_MOVE, 0);
 
to wyismail:<br>&nbsp; 直接用SC_MOVE,效果就像是你选择了窗体控制菜单的移动菜单,需要按方向键才能移动!<br>SC_MOVE + 2就可以直接让控件跟着你的鼠标动了
 
但是我需要是控件的大小也改变的那种拖动啊<br>大哥行行好<br>再教个招
 
抄的,能拖动或改变大小,但只对TWinControl类有效:<br>---------------------------------------<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; ExtCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Panel1: TPanel;<br>&nbsp; &nbsp; procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,<br>&nbsp; &nbsp; &nbsp; Y: Integer);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure ManipulateControl(Control: TControl; Shift: TShiftState; X, Y, Precision: integer);<br>var<br>&nbsp; &nbsp;SC_MANIPULATE: Word;<br>begin<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; //光标在控件的最左侧**********************************************************<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; &nbsp; &nbsp; &nbsp;if (X&lt;=Precision) and (Y&gt;Precision) and (Y&lt;Control.Height-Precision)<br>&nbsp; then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SC_MANIPULATE &nbsp;:= $F001;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Control.Cursor := crSizeWE;<br>&nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; //光标在控件的最右侧**********************************************************<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; else if (X&gt;=Control.Width-Precision) and (Y&gt;Precision) and (Y&lt;Control.Height-Precision)<br>&nbsp; then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SC_MANIPULATE &nbsp;:= $F002;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Control.Cursor := crSizeWE;<br>&nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; //光标在控件的最上侧**********************************************************<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; else if (X&gt;Precision) and (X&lt;Control.Width-Precision) and (Y&lt;=Precision)<br>&nbsp; then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SC_MANIPULATE &nbsp;:= $F003;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Control.Cursor := crSizeNS;<br>&nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; //光标在控件的左上角**********************************************************<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; else if (X&lt;=Precision) and (Y&lt;=Precision)<br>&nbsp; then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SC_MANIPULATE &nbsp;:= $F004;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Control.Cursor := crSizeNWSE;<br>&nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; //光标在控件的右上角**********************************************************<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; else if (X&gt;=Control.Width-Precision) and (Y&lt;=Precision)<br>&nbsp; then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SC_MANIPULATE &nbsp;:= $F005;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Control.Cursor := crSizeNESW &nbsp; &nbsp;;<br>&nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; //光标在控件的最下侧**********************************************************<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; else if (X&gt;Precision) and (X&lt;Control.Width-Precision) and (Y&gt;=Control.Height-Precision)<br>&nbsp; then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SC_MANIPULATE &nbsp;:= $F006;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Control.Cursor := crSizeNS;<br>&nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; //光标在控件的左下角**********************************************************<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; else if (X&lt;=Precision) and (Y&gt;=Control.Height-Precision)<br>&nbsp; then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SC_MANIPULATE &nbsp;:= $F007;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Control.Cursor := crSizeNESW;<br>&nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; //光标在控件的右下角**********************************************************<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; else if (X&gt;=Control.Width-Precision) and (Y&gt;=Control.Height-Precision)<br>&nbsp; then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SC_MANIPULATE &nbsp;:= $F008;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Control.Cursor := crSizeNWSE;<br>&nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; //光标在控件的客户区(移动整个控件)******************************************<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; else if (X&gt;5) and (Y&gt;5) and (X&lt;Control.Width-5) and (Y&lt;Control.Height-5)<br>&nbsp; then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SC_MANIPULATE &nbsp;:= $F009;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Control.Cursor := crSizeAll;<br>&nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; else begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SC_MANIPULATE := $F000;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Control.Cursor := crDefault;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>&nbsp; if Shift=[ssLeft] then<br>&nbsp; begin<br>&nbsp; &nbsp; ReleaseCapture;<br>&nbsp; &nbsp; Control.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);<br>&nbsp; end;<br>end;<br><br><br><br>procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,<br>&nbsp; Y: Integer);<br>begin<br>&nbsp; //Caption := IntToStr(X) + '/' + IntToStr(Y);<br>&nbsp; ManipulateControl((Panel1 as TControl), Shift, X, Y, 10);<br>end;<br><br>end.<br>&nbsp;
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部