How can I use pen pressure property in delphi?

Viewed 235

I'm use this code for get pressure property but does not work. Why GetPointerPenInfo function return false? LastError function return 87 (incorrect parameter)

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.
1 Answers

You are passing an uninitialized pointer to GetPointerPenInfo(). Try this instead:

procedure TForm1.PenEvent(var msg: TWMPointerUpdate);
var
  Info: TPointerPenInfo;
begin
  if not GetPointerPenInfo(msg.pointerId, @Info) then RaiseLastOSError;
  Label1.Caption := IntToStr(Info.pressure);
end;
Related