After reading a large number of documents, I found out that the correct way:
Intercept EventInfo.GestureID to determine the desired command in my case with the scaling command, after which you should read EventInfo.Flags and determine if it is gfBegin so that you can cache the first location point (x, y) and the first distance and when the flag is different , then gfBegin you do your calculations using the first and current points (EventInfo.Location)
The main command should be like this:
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;
There is sample code written in C #, available in the Windows v7.0 SDK, which can be used as a link and helps me lote.
source share