如何模拟鼠标的拖拽行为. Delphi / Windows SDK/APIhttp://www.delphi2007.net/DelphiAPI/html/delphi_20061112235944246.html
我想用鼠标模拟拖拽某一表格的列行为,就是把第一列拖到第五列寻样.
计算好目标窗口的坐标,然后把该窗口置为前台,再用类似下面这样的代码试试:
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
楼上的方法偶试过,但一直没有成功.
测试情况是wm_lbuttondown, wm_mousemove,wm_lbuttonup消息都捕获了
(坐标是没有问题的.)
就是没有实现拖动列的效果.
偶是在DELPHI下试的.
function MouseToScreen(mVertical: Boolean; mMouse: Integer): Integer;
begin
case mVertical of
False: Result := Round(mMouse * (MAXWORD / Screen.Width));
else Result := Round(mMouse * (MAXWORD / Screen.Height));
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
vPoint: TPoint;
begin
vPoint := Panel1.ClientToScreen(Point(1, 1));
mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE,
MouseToScreen(False, vPoint.X), MouseToScreen(True, vPoint.Y), 0, 0);
mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTDOWN,
MouseToScreen(False, vPoint.X), MouseToScreen(True, vPoint.Y), 0, 0);
Dec(vPoint.X, 200);
Dec(vPoint.Y, 200);
mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE,
MouseToScreen(False, vPoint.X), MouseToScreen(True, vPoint.Y), 0, 0);
mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP,
MouseToScreen(False, vPoint.X), MouseToScreen(True, vPoint.Y), 0, 0);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Panel1.DragKind := dkDock;
Panel1.DragMode := dmAutomatic;
end;
TO 楼上:
非常感谢!
可是对TStringGrid列的拖动还是不行.