无法通过TPANEL来移动窗口,WHY???HELP ME ( 积分: 50 )

  • 主题发起人 主题发起人 tinyliu2005
  • 开始时间 开始时间
T

tinyliu2005

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, ExtCtrls, StdCtrls;<br><br>type<br><br> &nbsp; &nbsp;tpnl = class( TPanel )<br> &nbsp; &nbsp;private<br> &nbsp; &nbsp; &nbsp; &nbsp;procedure WMNCHITTEST(var Message :TWMNCHITTEST); message WM_NCHITTEST;<br><br><br> &nbsp; &nbsp;end;<br><br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Memo1: TMemo;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure FormDestroy(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp;pnl:tpnl;<br> &nbsp; &nbsp; &nbsp; &nbsp;procedure WMNCHITTEST(var Message :TWMNCHITTEST); message WM_NCHITTEST;<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>{ tpnl }<br><br>procedure tpnl.WMNCHITTEST(var Message: TWMNCHITTEST);<br>var<br> &nbsp; &nbsp;dw:integer;<br>begin<br> &nbsp; &nbsp;dw := message.YPos ;<br> &nbsp; &nbsp;dw := dw shl 16;<br> &nbsp; &nbsp;dw := dw + message.XPos;<br>if not (csDesigning in ComponentState) then<br> &nbsp; &nbsp;SendMessage(application.MainForm.Handle ,WM_NCHITTEST,0,dw);<br> &nbsp;inherited;<br><br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp; &nbsp;pnl:=tpnl.Create(self);<br> &nbsp; &nbsp;pnl.Color :=clblue;<br> &nbsp; &nbsp;pnl.Parent :=self;<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> &nbsp; &nbsp;pnl.Free;<br>end;<br><br>procedure TForm1.WMNCHITTEST(var Message: TWMNCHITTEST);<br>begin<br> &nbsp; &nbsp;inherited;<br> &nbsp; &nbsp;message.Result :=htcaption;<br> &nbsp; &nbsp;memo1.Lines.Add(inttostr(memo1.Lines.Count +1)+': x = '+<br> &nbsp; &nbsp;inttostr(message.XPos )+'; y = '+<br> &nbsp; &nbsp; &nbsp; inttostr(message.yPos ) );//鼠标在pnl上移动主窗口可以收到此消息,窗口就是不能移动,不懂!<br>end;<br><br>end.<br>
 
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, ExtCtrls, StdCtrls;<br><br>type<br><br> &nbsp; &nbsp;tpnl = class( TPanel )<br> &nbsp; &nbsp;private<br> &nbsp; &nbsp; &nbsp; &nbsp;procedure WMNCHITTEST(var Message :TWMNCHITTEST); message WM_NCHITTEST;<br><br><br> &nbsp; &nbsp;end;<br><br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Memo1: TMemo;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure FormDestroy(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp;pnl:tpnl;<br> &nbsp; &nbsp; &nbsp; &nbsp;procedure WMNCHITTEST(var Message :TWMNCHITTEST); message WM_NCHITTEST;<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>{ tpnl }<br><br>procedure tpnl.WMNCHITTEST(var Message: TWMNCHITTEST);<br>var<br> &nbsp; &nbsp;dw:integer;<br>begin<br> &nbsp; &nbsp;dw := message.YPos ;<br> &nbsp; &nbsp;dw := dw shl 16;<br> &nbsp; &nbsp;dw := dw + message.XPos;<br>if not (csDesigning in ComponentState) then<br> &nbsp; &nbsp;SendMessage(application.MainForm.Handle ,WM_NCHITTEST,0,dw);<br> &nbsp;inherited;<br><br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp; &nbsp;pnl:=tpnl.Create(self);<br> &nbsp; &nbsp;pnl.Color :=clblue;<br> &nbsp; &nbsp;pnl.Parent :=self;<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> &nbsp; &nbsp;pnl.Free;<br>end;<br><br>procedure TForm1.WMNCHITTEST(var Message: TWMNCHITTEST);<br>begin<br> &nbsp; &nbsp;inherited;<br> &nbsp; &nbsp;message.Result :=htcaption;<br> &nbsp; &nbsp;memo1.Lines.Add(inttostr(memo1.Lines.Count +1)+': x = '+<br> &nbsp; &nbsp;inttostr(message.XPos )+'; y = '+<br> &nbsp; &nbsp; &nbsp; inttostr(message.yPos ) );//鼠标在pnl上移动主窗口可以收到此消息,窗口就是不能移动,不懂!<br>end;<br><br>end.<br>
 
不是窗体本身触发好象不行
 
procedure TForm1.Panel1MouseDown(...);<br>begin<br> &nbsp;ReleaseCapture;<br> &nbsp;SendMessage(handle,WM_SYSCOMMAND,SC_MOVE+HTCAPTION,0);<br>end;
 
同意楼上的方法。
 
高手就是高手!!!!!!!!!!!!!!!!!
 
后退
顶部