Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi Lazarus中是否有GetMouseMovePointsEx函数?_Delphi_Lazarus - Fatal编程技术网

Delphi Lazarus中是否有GetMouseMovePointsEx函数?

Delphi Lazarus中是否有GetMouseMovePointsEx函数?,delphi,lazarus,Delphi,Lazarus,在另一个问题中,我问: 函数GetMouseMovePointsEx引起了我的注意,但是在Lazarus我找不到这个函数 他提到,在DelphiXe6中,它位于Winapi.Windows.pas中,在Lazarus中,尽管它不在Windows.pas中 我知道Lazarus绝对不是Delphi的复制品,但这个函数听起来可能是我在另一个问题中寻找的答案。我只是很难找到它的位置,甚至很难得到任何关于它的Delphi文档。我有DelphiXE,但现在它还没有安装,我的项目是用Lazarus编写的 我

在另一个问题中,我问:

函数
GetMouseMovePointsEx
引起了我的注意,但是在Lazarus我找不到这个函数

他提到,在DelphiXe6中,它位于
Winapi.Windows.pas
中,在Lazarus中,尽管它不在
Windows.pas

我知道Lazarus绝对不是Delphi的复制品,但这个函数听起来可能是我在另一个问题中寻找的答案。我只是很难找到它的位置,甚至很难得到任何关于它的Delphi文档。我有DelphiXE,但现在它还没有安装,我的项目是用Lazarus编写的

我在文件中找到了。。。从Lazarus IDE以安装文件夹为目标进行搜索,返回的唯一结果来自以下fpc来源之一:

lazarus\fpc\2.6.4\source\packages\winunits-jedi\src\jwawinuser.pas

我不确定我是否应该使用上述装置,或者Lazarus是否有一个与
GetMouseMovePointsEx不同的变体?

使用Lazarus的人是否有过使用
GetMouseMovePointsEx
的经验?如果有,我在哪里可以找到


谢谢。

此函数作为Win32库的一部分实现。它不是一个Delphi或FPC功能,而不是一个C++或VB函数。您可以从Win32导入它

在Delphi中,这种导入是通过在
Windows
单元中声明函数来实现的。如果你检查这个单元的源代码,你会发现很多类型和常量声明,以及函数。这些函数通常使用
external
关键字来实现,该关键字表示实现在该代码之外。
Windows
单元被称为标题翻译。也就是说,它是来自Win32 SDK的C/C++头文件的翻译

因此,您需要使用此函数进行标题转换。绝地首领的翻译是最常见的选择。看来你已经找到了。如果随FPC提供的版本满足您的需要,请使用它们


有时,您可能会发现自己处于进展的最前沿,需要使用任何标准标题翻译中未包含的函数。在这种情况下,通常很简单,可以自己进行翻译

下面是一个使用Delphi的快速示例。你仍然需要做的是过滤掉你已经收到的分数

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's 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;

你找到了。jwawinuser.pas单位来自绝地图书馆,没有理由不使用它。当然,只有当你瞄准Windows平台,因为该单元(和功能)是特定于平台的。@特拉玛你让我想到,如果我在Lazarus项目中使用
Windows.pas
,这是否也意味着该程序不会在其他平台上运行?是的。这是正确的。64位窗口被排除。@Blobby当然了。一旦您开始直接调用Win32 API函数,您就可以将自己绑定到Win32。我会尝试将定义从jwawinuser复制到自己的源代码中,并让它使用windows单元类型。至少这给了你在win64上战斗的机会。绝地头像并不是真正的64位清晰,至少不是FPC提供的版本。@Marco,但它们编译正确吗?在这种情况下,只有当你称之为虚假翻译时,你才会遇到问题。就像Emba的翻译一样,也不是64位的干净!其背后的思想是,许多64位数据都是在记录类型和字段的打包中,这些字段是用指针而不是整数进行缩放的(要么是因为翻译错误,要么是基于较旧的SDK并在以后的SDK中重述)。我不知道Embarcadero的Windows单元的(64位)状态。我用XE3做了一个64位的服务,也就是说,其余的工作应用程序都是32位的。据我所知,FPC Windows单元在这方面比FPC发行版中的绝地单元要好。刚刚在Lazarus测试了你的演示,看起来还可以。您需要将这些单元添加到界面部分的其他人注意:
jwaWinUser
jwaWinType
。我现在将尝试在我的程序中实现,看看结果是否良好,谢谢。问题当然是关于如何访问该函数,而不是提供如何调用该函数的演示。这就是我包含GetMouseMovePointsEx定义的原因。但我想我肯定错过了别的东西。@DavidHeffernan这是我的错误,这个问题不知怎么地与这个问题联系在一起了: