L
likingzhe
Unregistered / Unconfirmed
GUEST, unregistred user!
这是一个无窗口的程序,请江湖老大帮帮忙,程序可以编译运行,你们没有驱动,可能会报错,这个不影响。我有这样一个需要要解决,程序是个2点的触摸程序,已实现。可它是个无窗口的程序,我无法把2个触摸坐标点的位置取出来或者传递出来。gp1,gp2,大侠们看程序就明白了。我现在想把这2个坐标点的值取出来,并把这2个点的坐标值传递给一个ini文件。例如,touchTwo.ini第一点x值=300第一点y值=400第二点x值=100第二点y值=600基本是这个意思,有可能不是xy值,可能是(长,宽,高,底)这样的四个值,看程序就明白了,请大侠们,帮我解决下,谢谢注意:把代码复制后另存为.dpr文件即可编译运行!program MultiTouSDK;uses Windows, Messages, SysUtils;type MTouchPoint = packed record x1: Integer; y1: Integer; x2: Integer; y2: Integer; end;type _TouchData = record dwTouchCount: DWORD; x1: DWORD; y1: DWORD; x2: DWORD; y2: DWORD; end; PointData = array[0..1] of _TouchData;const AppName = 'MultiTouSDK';var AppWnd: HWND; Msg: TMsg; WndClass: TWndClass; gBrBackground: HBRUSH; gCount: Integer = 0; gP1, gP2: MTouchPoint; function StartComDevice(nport: Integer; bTransform: Boolean): Integer; cdecl; external 'MultiTouchSDK.dll'; function RegistCallback(hMultTouchCallBack: PChar): Integer; cdecl; external 'MultiTouchSDK.dll'; function StopComDevice(): Integer; cdecl; external 'MultiTouchSDK.dll';function MultTouchCallBack(const pd: PointData; Cnt: Integer): Integer; stdcall; // 用 stdcall 定义回调函数var Rect: TRect; Scx, Scy: Integer;begin Scx := GetSystemMetrics(SM_CXSCREEN); Scy := GetSystemMetrics(SM_CYSCREEN); Rect.Left := 0; Rect.Top := 0; Rect.Right := Scx; Rect.Bottom := Scy; // 注:每个点都有两对坐标,即左上角和右下角坐标 if Cnt > 0 then // Cnt表示触摸的点数,1表示单点点触摸 begin gP1.x1 := pd[0].x1; // 单点触摸时该点的左上角x轴坐标 gP1.x2 := pd[0].x2; // 单点触摸时该点的右下角x轴坐标 gP1.y1 := pd[0].y1; // 单点触摸时该点的左上角y轴坐标 gP1.y2 := pd[0].y2; // 单点触摸时该点的右下角y轴坐标 if Cnt > 1 then begin gP2.x1 := pd[1].x1; // 两点触摸时第二点的左上角x轴坐标 gP2.x2 := pd[1].x2; // 两点触摸时第二点的右下角x轴坐标 gP2.y1 := pd[1].y1; // 两点触摸时第二点的左上角y轴坐标 gP2.y2 := pd[1].y2; // 两点触摸时第二点的右下角y轴坐标 end; end; gCount := Cnt; InvalidateRect(AppWnd, @Rect, False); UpdateWindow(AppWnd); end;function WndProc(Wnd: HWND; Msg, wParam: Word; lParam: LongInt): LongInt; stdcall;var Rect: TRect; Scx, Scy: Integer; DC: HDC; Ps: TPaintStruct; hBrushY, hBrushOld: HBRUSH;begin case Msg of WM_DESTROY: begin StopComDevice(); // 触摸屏停止 PostQuitMessage(0); end; WM_KEYUP: if wParam = VK_ESCAPE then // 按下 ESC 键 PostQuitMessage(0); WM_COMMAND: if LOWORD(wParam) = WM_CLOSE then DestroyWindow(Wnd); WM_PAINT: begin DC := BeginPaint(Wnd, Ps); Scx := GetSystemMetrics(SM_CXSCREEN); Scy := GetSystemMetrics(SM_CYSCREEN); Rect.Left := 0; Rect.Top := 0; Rect.Right := Scx; Rect.Bottom := Scy; FillRect(DC, Rect, gBrBackground); SetTextColor(DC, RGB(255, 128, 64)); SetBkMode(DC, TRANSPARENT); TextOut(DC, Round(Rect.Right / 2 - 100), 20, 'Please press ESC key to cancel.', 31); hBrushY := CreateSolidBrush(RGB(255, 128, 64)); hBrushOld := HBRUSH(SelectObject(DC, hBrushY)); if gCount > 0 then begin Rect.Left := Round(gP1.x1 * Scx / 4096); Rect.Right := Round(gP1.x2 * Scx / 4096); Rect.Top := Round(gP1.y1 * Scy / 4096); Rect.Bottom := Round(gP1.y2 * Scy / 4096); Ellipse(DC, Rect.Left - 5, Rect.Top - 5, Rect.Right, Rect.Bottom); if gCount > 1 then begin Rect.Left := Round(gP2.x1 * Scx / 4096); Rect.Right := Round(gP2.x2 * Scx / 4096); Rect.Top := Round(gP2.y1 * Scy / 4096); Rect.Bottom := Round(gP2.y2 * Scy / 4096); Ellipse(DC, Rect.Left - 5, Rect.Top - 5, Rect.Right, Rect.Bottom); end; DeleteObject(hBrushY); DeleteObject(hBrushOld); end; EndPaint(Wnd, Ps); end; end; WndProc := DefWindowProc(Wnd, Msg, wParam, lParam);end; begin if FindWindow(AppName, nil) <> 0 then Halt; FillChar(WndClass, SizeOf(WndClass), 0); with WndClass do begin style := CS_HREDRAW or CS_VREDRAW; lpfnWndProc := @WndProc; // 取回调函数 WndProc 的地址 hInstance := SysInit.HInstance; // 实例句柄 hIcon := LoadIcon(hInstance, 'MAINICON'); hCursor := LoadCursor(hInstance, IDC_ARROW); lpszClassName := AppName; // 窗口类名 end; RegisterClass(WndClass); // 注册窗口类 gBrBackground := CreateSolidBrush(RGB(0, 128, 255)); AppWnd := CreateWindow(AppName, nil, WS_POPUP or WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), 0, 0, HInstance, nil); if AppWnd > 0 then begin ShowWindow(AppWnd, SW_NORMAL); UpdateWindow(AppWnd); RegistCallback(@MultTouchCallBack); // 注册回调函数 StartComDevice(0, True); // 启动 COM 口的触摸屏 end; while GetMessage(Msg, 0, 0, 0) do begin TranslateMessage(Msg); DispatchMessage(Msg); end;end.