我将此代码用于获取压力属性,但不起作用。为什么GetPointerPenInfo
函数返回false?
LastError
函数返回87(参数错误)
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Winapi.wmPointer, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
private
{ Private declarations }
public
{ Public declarations }
procedure PenEvent(var msg: TWMPointerUpdate); message WM_POINTERUPDATE;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
{ TForm1 }
procedure TForm1.PenEvent(var msg: TWMPointerUpdate);
var
pInfo: PPointerPenInfo;
begin
if GetPointerPenInfo(msg.pointerId, pInfo) then
Label1.Caption := inttostr(pInfo.pressure);
end;
end.
答案 0 :(得分:3)
您正在将未初始化的指针传递给GetPointerPenInfo()
。尝试以下方法:
procedure TForm1.PenEvent(var msg: TWMPointerUpdate);
var
Info: TPointerPenInfo;
begin
if not GetPointerPenInfo(msg.pointerId, @Info) then RaiseLastOSError;
Label1.Caption := IntToStr(Info.pressure);
end;