如何控制窗口移动位置?(100分)

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

cAkk

Unregistered / Unconfirmed
GUEST, unregistred user!
当用鼠标拖动窗口时,也就是说,当屏幕上出现虚线窗口边框时,<br>程序应该接受到什么消息?<br><br>我想让我的程序能够像photoshop的工具子窗口那样,在拖动的时候<br>可以自动靠边,比如当拖动位置接近屏幕边缘的时候,能够自动将<br>虚线框位置移动到屏幕边缘.<br><br>好像和WM_MOVING有关
 
你可以直接从鼠标的位置来判断嘛.<br>或者更精确一点,用鼠标位置和窗体上鼠标距窗体边框的距离来判断.
 
判断之后怎样修正虚线框的位置呢?
 
另外,我在什么事件里判断鼠标位置呢?
 
现在的问题是: 我的程序根本接受不到WM_MOVING消息!!!????
 
处理WM_SIZING消息。<br>Copied from Win32 API Help:<br>The WM_SIZING message is sent to a window that the user is resizing. <br>By processing this message, an application can monitor the size and <br>position of the drag rectangle and, if needed, change its size or <br>position.<br>
 
实在抱歉,刚才和别人说了几句,把大侠您的问题看错了,Sorry.
 
//效果不太好<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; procedure MyMouseMove(var Message:TMessage);message WM_MOVING;<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>uses Unit2;<br><br>{$R *.DFM}<br><br>procedure TForm1.MyMouseMove(var Message: TMessage);<br>begin<br>&nbsp; inherited;<br>&nbsp; if PRECT(Message.lParam)^.Left&lt;5 then<br>&nbsp; begin<br>&nbsp; &nbsp; form2.close;<br>&nbsp; &nbsp; Message.Result:=1;<br>&nbsp; &nbsp; ReleaseCapture;<br>&nbsp; &nbsp; MoveWindow(Handle,PRECT(Message.lParam)^.Left,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRECT(Message.lParam)^.Top,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRECT(Message.lParam)^.Right-PRECT(Message.lParam)^.Left,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRECT(Message.lParam)^.Bottom-PRECT(Message.lParam)^.Top,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; True);<br>&nbsp; end;<br>end;
 
直接修改Message里的Rect就可以了:<br>&nbsp; with TRect(Pointer(Msg.LParam)^) do<br>&nbsp; begin<br>&nbsp; &nbsp;Top := 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//在此处改变位置和大小<br>&nbsp; &nbsp;Left := 0;<br>&nbsp; &nbsp;Right := Width;<br>&nbsp; &nbsp;Bottom := Height;<br>&nbsp; end;<br>
 
这样改就好多了。<br><br>procedure TForm1.MyMouseMove(var Message: TMessage);<br>begin<br>&nbsp; inherited;<br>&nbsp; if PRECT(Message.lParam)^.Left&lt;5 then<br>&nbsp; begin<br>&nbsp; &nbsp; MoveWindow(Handle,PRECT(Message.lParam)^.Left,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRECT(Message.lParam)^.Top,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRECT(Message.lParam)^.Right-PRECT(Message.lParam)^.Left,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRECT(Message.lParam)^.Bottom-PRECT(Message.lParam)^.Top,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; True);<br>&nbsp; &nbsp; Message.Result:=1;<br>&nbsp; &nbsp; ReleaseCapture;<br>&nbsp; end;<br>end;
 
用前卫和Zephyr的方法结合起来就搞定了!<br><br>前卫:我只想修正虚线框位置,不想立即movewindow,所以不能Realeasecaptrue,<br>&nbsp; &nbsp; &nbsp;不能movewindow.
 
多人接受答案了。
 
5~~~~~~~~~,刚去试了一下,打算回来贴文章,结果迟拉,5~~~~~~~
 
后退
顶部