tags:

views:

108

answers:

2

Hello,

I have the following code called on WM_MOVE

procedure TForm15.WMMove(var Message: TMessage);
begin
if( (((TWMMove(Message).XPos + Self.Width >= Form14.Left) and (TWMMove(Message).XPos <= Form14.Left)) or
  ((TWMMove(Message).XPos <= Form14.Left + Form14.Width) and (TWMMove(Message).XPos >= Form14.Left))) and
(((TWMMove(Message).YPos + Self.Height >= Form14.Top) and (TWMMove(Message).YPos <= Form14.Top)) or
  ((TWMMove(Message).YPos <= Form14.Top + Form14.Height) and (TWMMove(Message).YPos >= Form14.Top))))
 then begin
   Self.DragKind := dkDock;
 end else Self.DragKind := dkDrag;
end;

It's probably the ugliest if statement you've seen in your life,but that's not the question. :)

It's supposed to change DragKind if the current form(Self) is somewhere inside the mainForm(Form14).

However,When It sets DragKind to dkDock ,it doesn't make the currentForm(Self) dockable unless the user stops moving the form and start moving it again,so I'm trying to do the following:

If the result from the statement above is non zero and dkDock is set then Send the following messages to the form:

WM_EXITSIZEMOVE //stop moving the form

WM_ENTERSIZEMOVE //start movement again

However,I don't know how to do it:

SendMessage(Self.Handle,WM_EXITSIZEMOVE,?,?);

I tried using random parameters(1,1) ,but no effect.Maybe that's not the right way?

+1  A: 

This is a notification message, it does not cause the form to stop moving.
And both parameter are ignored (unused).

François
Well,my point was that I have to make the form stop moving,do you know a message that does that?
John
+2  A: 

It looks like those two messages are notifications - directly sending them probably doesn't do anything. As Raymond Chen once said (horribly paraphrased), directly sending these messages and expecting action is like trying to refill your gas tank by moving the needle in the gauge.

WM_SIZING and WM_MOVING are messages that you can use to monitor a user changing a window's size and position, and block further changes.

From MSDN:

lParam

Pointer to a RECT structure with the current position of the window, in screen coordinates. To change the position of the drag rectangle, an application must change the members of this structure.

So you can change the members to force the window to remain in a single position.

Michael
Can you suggest a way to make the form stop moving?
John
You modify the rect passed to WM_MOVING to keep the window in one position.
Michael
I did this "Message.LParam := 0;" without the other code,but the form continues to change its possition as normal.
John
@John: You missed Michael's point entirely. lParam with WM_SIZING and WM_MOVING is a Rect. You can use TRect(lParam) and modify it to keep the window exactly where it is, as in TRect(lParam).Left := SomeValue;
Ken White