在阅读了大量文档后,我发现正确的做法是:
拦截 EventInfo.GestureID 以识别在我的情况下所需的命令缩放命令,之后您应该阅读 EventInfo.Flags 并确定它是否是 gfBegin 以便您可以缓存第一个位置点 (x,y) 和第一个距离,当标志不同时,gfBegin 使用 firstpoint 和 currentpoint (EventInfo.Location) 执行计算
基本命令应该是这样的:
case EventInfo.GestureID of
igiZoom:
begin
if (EventInfo.Flags = [gfBegin]) then
begin
FLastDistance := EventInfo.Distance;
FFirstPoint.X := EventInfo.Location.X;
FFirstPoint.Y := EventInfo.Location.Y;
FFirstPoint := ScreenToClient(FFirstPoint);
if (FSecondPoint.X = 0) and (FSecondPoint.Y = 0) then
begin
FSecondPoint.X := EventInfo.Location.X + 10;
FSecondPoint.Y := EventInfo.Location.Y + 10;
FSecondPoint := ScreenToClient(FSecondPoint);
end;
//ZoomCenter is a local TPoint var
ZoomCenter.Create(((FFirstPoint.X + FSecondPoint.X) div 2),
((FFirstPoint.Y + FSecondPoint.Y) div 2));
//Apply the zoom to the object
FDrawingObject.Zoom(EventInfo.Distance / FLastDistance, ZoomCenter.X, ZoomCenter.Y);
Invalidate;
end
else
begin
FSecondPoint.X := EventInfo.Location.X;
FSecondPoint.Y := EventInfo.Location.Y;
FSecondPoint := ScreenToClient(FSecondPoint);
ZoomCenter.Create(((FFirstPoint.X + FSecondPoint.X) div 2),
((FFirstPoint.Y + FSecondPoint.Y) div 2));
FDrawingObject.Zoom(EventInfo.Distance / FLastDistance, ZoomCenter.X, ZoomCenter.Y);
Invalidate;
//Update with the new values for next interaction
FFirstPoint := FSecondPoint;
FLastDistance := EventInfo.Distance;
end;
Windows v7.0 SDK 中有一个用 c# 编写的示例代码,可以作为参考,对我有很大帮助。