Is there a GetMouseMovePointsEx function in Lazarus?

In this other question, I asked: Draw on paintwork - How to keep up with mouse movements without delay? ...

The feature GetMouseMovePointsEx

was brought to my attention by Sebastian Z , however, in Lazarus I cannot find this feature.

He mentioned that in Delphi XE6 he is in Winapi.Windows.pas

, in Lazare, although he is not in Windows.pas

.

I understand that Lazarus is by no means an exact copy of Delphi, but this feature sounds like it might be the answer I'm looking for in this other question. I'm just having a hard time finding where it is, and even getting any Delphi documentation. I have Delphi XE but it is not installed right now and my project is written in Lazarus.

I found a file search ... a search from the Lazarus IDE focused on the install folder and the only result that came back was from one of the fpc sources in:

Lazarus \ FPC \ 2.6.4 \ Source \ Packages \ winunits-JEDI \ SRC \ jwawinuser.pas

I'm not sure if I should use the above block or not, or if Lazarus has another option GetMouseMovePointsEx?

Anyone using Lazarus has experience with GetMouseMovePointsEx

, and if so, where can I find it?

Thank.

+1


source to share


2 answers


Here's a quick example using Delphi. What else you need to do is filter out the points you have already received.



type
  TMouseMovePoints = array of TMouseMovePoint;
const
  GMMP_USE_HIGH_RESOLUTION_POINTS = 2;

function GetMouseMovePointsEx(cbSize: UINT; var lppt: TMouseMovePoint; var lpptBuf: TMouseMovePoint; nBufPoints: Integer; resolution: DWORD): Integer; stdcall; external 'user32.dll';

function GetMessagePosAsTPoint: TPoint;
type
  TMakePoints = packed record
    case Integer of
      1: (C : Cardinal);
      2: (X : SmallInt; Y : SmallInt);
  end;
var
  Tmp : TMakePoints;
begin
  Tmp.C := GetMessagePos;
  Result.X := Tmp.X;
  Result.Y := Tmp.Y;
end;

function GetMousePoints: TMouseMovePoints;
var
  nVirtualWidth: Integer;
  nVirtualHeight: Integer;
  nVirtualLeft: Integer;
  nVirtualTop: Integer;
  cpt: Integer;
  mp_in: MOUSEMOVEPOINT;
  mp_out: array[0..63] of MOUSEMOVEPOINT;
  mode: Integer;
  Pt: TPoint;
  I: Integer;
begin
  Pt := GetMessagePosAsTPoint;

  nVirtualWidth := GetSystemMetrics(SM_CXVIRTUALSCREEN) ;
  nVirtualHeight := GetSystemMetrics(SM_CYVIRTUALSCREEN) ;
  nVirtualLeft := GetSystemMetrics(SM_XVIRTUALSCREEN) ;
  nVirtualTop := GetSystemMetrics(SM_YVIRTUALSCREEN) ;
  cpt := 0 ;
  mode := GMMP_USE_DISPLAY_POINTS ;

  FillChar(mp_in, sizeof(mp_in), 0) ;
  mp_in.x := pt.x and $0000FFFF ;//Ensure that this number will pass through.
  mp_in.y := pt.y and $0000FFFF ;
  mp_in.time := GetMessageTime;
  cpt := GetMouseMovePointsEx(SizeOf(MOUSEMOVEPOINT), mp_in, mp_out[0], 64, mode) ;

  for I := 0 to cpt - 1 do
  begin
   case mode of
     GMMP_USE_DISPLAY_POINTS:
       begin
         if (mp_out[i].x > 32767) then
            mp_out[i].x := mp_out[i].x - 65536;
         if (mp_out[i].y > 32767) then
            mp_out[i].y := mp_out[i].y - 65536;
       end;
   GMMP_USE_HIGH_RESOLUTION_POINTS:
     begin
      mp_out[i].x := ((mp_out[i].x * (nVirtualWidth - 1)) - (nVirtualLeft * 65536)) div nVirtualWidth;
      mp_out[i].y := ((mp_out[i].y * (nVirtualHeight - 1)) - (nVirtualTop * 65536)) div nVirtualHeight;
     end;
   end;
  end;

  if cpt > 0 then
  begin
    SetLength(Result, cpt);
    for I := 0 to cpt - 1 do
    begin
      Result[I] := mp_out[I];
    end;
  end
  else
    SetLength(Result, 0);
end;

// the following is for demonstration purposes only, it still needs some improvements like filtering out points that were already processed. But it good enough for painting a blue line on a TImage
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  MMPoints: TMouseMovePoints;
  Pt: TPoint;
  I: Integer;
begin
  Image1.Canvas.Pen.Color := clBlue;
  MMPoints := GetMousePoints;

  for I := 0 to Length(MMPoints) - 1 do
  begin
    Pt.x := MMPoints[I].x;
    Pt.y := MMPoints[I].y;
    Pt := Image1.ScreenToClient(Pt);
    if I = 0 then
      Image1.Canvas.MoveTo(PT.X, pt.y)
    else
      Image1.Canvas.LineTo(PT.X, pt.y);
  end;
end;

      

+1


source


This feature is implemented as part of the Win32 library. It is no longer a Delphi or FPC function than a C ++ or VB function. You are importing it from Win32.

In Delphi, this import is achieved by declaring a function in a module Windows

. If you research the source of this device, you will find many type and constant declarations as well as functions. These functions are usually implemented using a keyword external

that indicates that the implementation is external to this code. A block Windows

is a so-called translation of a title. That is, it is a translation of the C / C ++ header files from the Win32 SDK.



So, you need to broadcast the title with this function. JEDI headline translations are the most common choice. And it seems that you have already found them. If the versions that come with FPC serve your needs, then use them.

Sometimes you might find yourself on the edge of progress and use a feature that hasn't been included in any of the standard header translations. In this scenario, it is usually easy enough to do the translation yourself.

+1


source







All Articles