unit Main;interfaceuses Windows, Messages, SysUtils, Dialogs, Classes, Controls, Forms, StrUtils, StdCtrls;type TForm1 = class(TForm) btnTest: TButton; procedure btnTestClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormPaint(Sender: TObject); procedure FormShow(Sender: TObject); private public end;type _TouchData = record dwTouchCount: DWORD; x1: DWORD; y1: DWORD; x2: DWORD; y2: DWORD; end; PointData = ^_TouchData;var Form1: TForm1; gPointx: Integer = 0; gPointy: Integer = 0; gCount: Integer = 0; gP1, gP2: PointData; function StartComDevice(nport: Integer; bTransform: Boolean): Integer; stdcall; external 'MultiTouchSDK.dll'; function RegistCallback(hMultTouchCallBack: PChar): Integer; stdcall; external 'MultiTouchSDK.dll'; function StopComDevice(): Integer; stdcall; external 'MultiTouchSDK.dll';implementation{$R *.dfm}function MultTouchCallBack(const pd: PointData; Cnt: Integer): Integer; stdcall;var Rct: TRect; Scx, Scy: Integer;begin Scx := GetSystemMetrics(SM_CXSCREEN); Scy := GetSystemMetrics(SM_CYSCREEN); Rct.Left := 0; Rct.Top := 0; Rct.Right := Scx; Rct.Bottom := Scy; // 注:每个点都有两对坐标,即左上角和右下角坐标 if Cnt > 0 then // Cnt表示触摸的点数,1表示单点点触摸 begin gP1.x1 := pd.x1; // 单点触摸时该点的左上角x轴坐标 gP1.x2 := pd.x2; // 单点触摸时该点的右下角x轴坐标 gP1.y1 := pd.y1; // 单点触摸时该点的左上角y轴坐标 gP1.y2 := pd.y2; // 单点触摸时该点的右下角y轴坐标 if Cnt > 1 then begin gP2.x1 := pd.x1; // 两点触摸时第二点的左上角x轴坐标 gP2.x2 := pd.x2; // 两点触摸时第二点的右下角x轴坐标 gP2.y1 := pd.y1; // 两点触摸时第二点的左上角y轴坐标 gP2.y2 := pd.y2; // 两点触摸时第二点的右下角y轴坐标 end; end; gCount := Cnt; InvalidateRect(Form1.Handle, @Rect, False); // 或者用 Application.Handle UpdateWindow(Form1.Handle); // 或者用 Application.Handleend;procedure TForm1.FormShow(Sender: TObject);begin RegistCallback(@MultTouchCallBack); // 注册回调函数 StartComDevice(0, True); // 启动 COM 口的触摸屏end;procedure TForm1.btnTestClick(Sender: TObject);begin ShowMessageFmt('单点触摸时该点的左上角x轴坐标为:%d', [gP1.x1]);end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin StopComDevice; // 触摸屏停止end;// 根据 .cpp 的源码, 以下代码应该写在 WM_PAINT 消息中// 此处作为示例, 实际使用时可自行修改, 或许不必如此麻烦procedure TForm1.FormPaint(Sender: TObject); var Rct: TRect; Scx, Scy: Integer; vDC: HDC; Ps: TPaintStruct;begin Scx := GetSystemMetrics(SM_CXSCREEN); Scy := GetSystemMetrics(SM_CYSCREEN); Rct.Left := 0; Rct.Top := 0; Rct.Right := Scx; Rct.Bottom := Scy; vDC := BeginPaint(Self.Handle, Ps); if gCount > 0 then begin Rct.Left := Round(gP1.x1 * Scx / 4096); Rct.Right := Round(gP1.x2 * Scx / 4096); Rct.Top := Round(gP1.y1 * Scy / 4096); Rct.Bottom := Round(gP1.y2 * Scy / 4096); Ellipse(vDC, Rct.Left - 5, Rct.Top - 5, Rct.Right, Rct.Bottom); if gCount > 1 then begin Rct.Left := Round(gP2.x1 * Scx / 4096); Rct.Right := Round(gP2.x2 * Scx / 4096); Rct.Top := Round(gP2.y1 * Scy / 4096); Rct.Bottom := Round(gP2.y2 * Scy / 4096); Ellipse(vDC, Rct.Left - 5, Rct.Top - 5, Rct.Right, Rct.Bottom); end; end; EndPaint(Self.Handle, Ps);end;end.