多触摸学些

本文介绍如何使用Visual C++ 2010与Windows SDK for Windows 7开发多点触控应用程序,涵盖程序引导、调试技巧及手势学习等内容,并提供API函数、结构体、宏定义等详细资料。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

内容很多,我这里主要采用引用的形式说明:

1.程序引导篇:

 

基于Visual C++2010与windows SDK fo windows7开发Windows 7的多点触摸特性应用程序(1)

 

基于Visual C++2010与windows SDK fo windows7开发Windows 7的多点触摸特性应用程序(2)--手势识别应用

Build a Multitouch Gesture Application

 

2.调试篇

 

作为开发者对MT 应用程序进行测试的时候,当然需要MT 硬件设备的支持,否则我们无法判断程序是否能够正常运行。虽然现在市面上的MT 设备已经很多,但价格也都不菲。如果没有多点触控设备能否进行MT 程序的开发与测试呢?  答案当然是可以的。

 

Windows 7 安装多点触屏模拟器

 

 

3。手势学习

 

vs2010中学习, 直接将一些API函数,,结构体,宏定义等挖出来。

如:winbuser.h中

 

#if(WINVER >= 0x0601)
 
/*
 * Touch Input defines and functions
 */
 
/*
 * Touch input handle
 */
DECLARE_HANDLE(HTOUCHINPUT);
 
typedef struct tagTOUCHINPUT {
    LONG x;
    LONG y;
    HANDLE hSource;
    DWORD dwID;
    DWORD dwFlags;
    DWORD dwMask;
    DWORD dwTime;
    ULONG_PTR dwExtraInfo;
    DWORD cxContact;
    DWORD cyContact;
} TOUCHINPUT, *PTOUCHINPUT;
typedef TOUCHINPUT const * PCTOUCHINPUT;
 
 
/*
 * Conversion of touch input coordinates to pixels
 */
#define TOUCH_COORD_TO_PIXEL(l)         ((l) / 100)
 
/*
 * Touch input flag values (TOUCHINPUT.dwFlags)
 */
#define TOUCHEVENTF_MOVE            0x0001
#define TOUCHEVENTF_DOWN            0x0002
#define TOUCHEVENTF_UP              0x0004
#define TOUCHEVENTF_INRANGE         0x0008
#define TOUCHEVENTF_PRIMARY         0x0010
#define TOUCHEVENTF_NOCOALESCE      0x0020
#define TOUCHEVENTF_PEN             0x0040
#define TOUCHEVENTF_PALM            0x0080
 
/*
 * Touch input mask values (TOUCHINPUT.dwMask)
 */
#define TOUCHINPUTMASKF_TIMEFROMSYSTEM  0x0001  // the dwTime field contains a system generated value
#define TOUCHINPUTMASKF_EXTRAINFO       0x0002  // the dwExtraInfo field is valid
#define TOUCHINPUTMASKF_CONTACTAREA     0x0004  // the cxContact and cyContact fields are valid
 
WINUSERAPI
BOOL
WINAPI
GetTouchInputInfo(
    __in HTOUCHINPUT hTouchInput,               // input event handle; from touch message lParam
    __in UINT cInputs,                          // number of elements in the array
    __out_ecount(cInputs) PTOUCHINPUT pInputs,  // array of touch inputs
    __in int cbSize);                           // sizeof(TOUCHINPUT)
 
WINUSERAPI
BOOL
WINAPI
CloseTouchInputHandle(
    __in HTOUCHINPUT hTouchInput);                   // input event handle; from touch message lParam
 
 
/*
 * RegisterTouchWindow flag values
 */
#define TWF_FINETOUCH       (0x00000001)
#define TWF_WANTPALM        (0x00000002)
 
WINUSERAPI
BOOL
WINAPI
RegisterTouchWindow(
    __in HWND hwnd,
    __in ULONG ulFlags);
 
WINUSERAPI
BOOL
WINAPI
UnregisterTouchWindow(
    __in HWND hwnd);
 
WINUSERAPI
BOOL
WINAPI
IsTouchWindow(
    __in HWND hwnd,
    __out_opt PULONG pulFlags);
 
#endif /* WINVER >= 0x0601 */
 
 
#if(WINVER >= 0x0601)
 
/*
 * Gesture defines and functions
 */
 
/*
 * Gesture information handle
 */
DECLARE_HANDLE(HGESTUREINFO);
 
 
/*
 * Gesture flags - GESTUREINFO.dwFlags
 */
#define GF_BEGIN                        0x00000001
#define GF_INERTIA                      0x00000002
#define GF_END                          0x00000004
 
/*
 * Gesture IDs
 */
#define GID_BEGIN                       1
#define GID_END                         2
#define GID_ZOOM                        3
#define GID_PAN                         4
#define GID_ROTATE                      5
#define GID_TWOFINGERTAP                6
#define GID_PRESSANDTAP                 7
#define GID_ROLLOVER                    GID_PRESSANDTAP
 
/*
 * Gesture information structure
 *   - Pass the HGESTUREINFO received in the WM_GESTURE message lParam into the
 *     GetGestureInfo function to retrieve this information.
 *   - If cbExtraArgs is non-zero, pass the HGESTUREINFO received in the WM_GESTURE
 *     message lParam into the GetGestureExtraArgs function to retrieve extended
 *     argument information.
 */
typedef struct tagGESTUREINFO {
    UINT cbSize;                    // size, in bytes, of this structure (including variable length Args field)
    DWORD dwFlags;                  // see GF_* flags
    DWORD dwID;                     // gesture ID, see GID_* defines
    HWND hwndTarget;                // handle to window targeted by this gesture
    POINTS ptsLocation;             // current location of this gesture
    DWORD dwInstanceID;             // internally used
    DWORD dwSequenceID;             // internally used
    ULONGLONG ullArguments;         // arguments for gestures whose arguments fit in 8 BYTES
    UINT cbExtraArgs;               // size, in bytes, of extra arguments, if any, that accompany this gesture
} GESTUREINFO, *PGESTUREINFO;
typedef GESTUREINFO const * PCGESTUREINFO;
 
 
/*
 * Gesture notification structure
 *   - The WM_GESTURENOTIFY message lParam contains a pointer to this structure.
 *   - The WM_GESTURENOTIFY message notifies a window that gesture recognition is
 *     in progress and a gesture will be generated if one is recognized under the
 *     current gesture settings.
 */
typedef struct tagGESTURENOTIFYSTRUCT {
    UINT cbSize;                    // size, in bytes, of this structure
    DWORD dwFlags;                  // unused
    HWND hwndTarget;                // handle to window targeted by the gesture
    POINTS ptsLocation;             // starting location
    DWORD dwInstanceID;             // internally used
} GESTURENOTIFYSTRUCT, *PGESTURENOTIFYSTRUCT;
 
/*
 * Gesture argument helpers
 *   - Angle should be a double in the range of -2pi to +2pi
 *   - Argument should be an unsigned 16-bit value
 */
#define GID_ROTATE_ANGLE_TO_ARGUMENT(_arg_)     ((USHORT)((((_arg_) + 2.0 * 3.14159265) / (4.0 * 3.14159265)) * 65535.0))
#define GID_ROTATE_ANGLE_FROM_ARGUMENT(_arg_)   ((((double)(_arg_) / 65535.0) * 4.0 * 3.14159265) - 2.0 * 3.14159265)
 
/*
 * Gesture information retrieval
 *   - HGESTUREINFO is received by a window in the lParam of a WM_GESTURE message.
 */
WINUSERAPI
BOOL
WINAPI
GetGestureInfo(
    __in HGESTUREINFO hGestureInfo,
    __out PGESTUREINFO pGestureInfo);
 
/*
 * Gesture extra arguments retrieval
 *   - HGESTUREINFO is received by a window in the lParam of a WM_GESTURE message.
 *   - Size, in bytes, of the extra argument data is available in the cbExtraArgs
 *     field of the GESTUREINFO structure retrieved using the GetGestureInfo function.
 */
WINUSERAPI
BOOL
WINAPI
GetGestureExtraArgs(
    __in HGESTUREINFO hGestureInfo,
    __in UINT cbExtraArgs,
    __out_bcount(cbExtraArgs) PBYTE pExtraArgs);
 
/*
 * Gesture information handle management
 *   - If an application processes the WM_GESTURE message, then once it is done
 *     with the associated HGESTUREINFO, the application is responsible for
 *     closing the handle using this function. Failure to do so may result in
 *     process memory leaks.
 *   - If the message is instead passed to DefWindowProc, or is forwarded using
 *     one of the PostMessage or SendMessage class of API functions, the handle
 *     is transfered with the message and need not be closed by the application.
 */
WINUSERAPI
BOOL
WINAPI
CloseGestureInfoHandle(
    __in HGESTUREINFO hGestureInfo);
 
 
/*
 * Gesture configuration structure
 *   - Used in SetGestureConfig and GetGestureConfig
 *   - Note that any setting not included in either GESTURECONFIG.dwWant or
 *     GESTURECONFIG.dwBlock will use the parent window's preferences or
 *     system defaults.
 */
typedef struct tagGESTURECONFIG {
    DWORD dwID;                     // gesture ID
    DWORD dwWant;                   // settings related to gesture ID that are to be turned on
    DWORD dwBlock;                  // settings related to gesture ID that are to be turned off
} GESTURECONFIG, *PGESTURECONFIG;
 
/*
 * Gesture configuration flags - GESTURECONFIG.dwWant or GESTURECONFIG.dwBlock
 */
 
/*
 * Common gesture configuration flags - set GESTURECONFIG.dwID to zero
 */
#define GC_ALLGESTURES                              0x00000001
 
/*
 * Zoom gesture configuration flags - set GESTURECONFIG.dwID to GID_ZOOM
 */
#define GC_ZOOM                                     0x00000001
 
/*
 * Pan gesture configuration flags - set GESTURECONFIG.dwID to GID_PAN
 */
#define GC_PAN                                      0x00000001
#define GC_PAN_WITH_SINGLE_FINGER_VERTICALLY        0x00000002
#define GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY      0x00000004
#define GC_PAN_WITH_GUTTER                          0x00000008
#define GC_PAN_WITH_INERTIA                         0x00000010
 
/*
 * Rotate gesture configuration flags - set GESTURECONFIG.dwID to GID_ROTATE
 */
#define GC_ROTATE                                   0x00000001
 
/*
 * Two finger tap gesture configuration flags - set GESTURECONFIG.dwID to GID_TWOFINGERTAP
 */
#define GC_TWOFINGERTAP                             0x00000001
 
/*
 * PressAndTap gesture configuration flags - set GESTURECONFIG.dwID to GID_PRESSANDTAP
 */
#define GC_PRESSANDTAP                              0x00000001
#define GC_ROLLOVER                                 GC_PRESSANDTAP
 
#define GESTURECONFIGMAXCOUNT           256             // Maximum number of gestures that can be included
                                                        // in a single call to SetGestureConfig / GetGestureConfig
 
WINUSERAPI
BOOL
WINAPI
SetGestureConfig(
    __in HWND hwnd,                                     // window for which configuration is specified
    __in DWORD dwReserved,                              // reserved, must be 0
    __in UINT cIDs,                                     // count of GESTURECONFIG structures
    __in_ecount(cIDs) PGESTURECONFIG pGestureConfig,    // array of GESTURECONFIG structures, dwIDs will be processed in the
                                                        // order specified and repeated occurances will overwrite previous ones
    __in UINT cbSize);                                  // sizeof(GESTURECONFIG)
 
 
#define GCF_INCLUDE_ANCESTORS           0x00000001      // If specified, GetGestureConfig returns consolidated configuration
                                                        // for the specified window and it's parent window chain
 
WINUSERAPI
BOOL
WINAPI
GetGestureConfig(
    __in HWND hwnd,                                     // window for which configuration is required
    __in DWORD dwReserved,                              // reserved, must be 0
    __in DWORD dwFlags,                                 // see GCF_* flags
    __in PUINT pcIDs,                                   // *pcIDs contains the size, in number of GESTURECONFIG structures,
                                                        // of the buffer pointed to by pGestureConfig
    __inout_ecount(*pcIDs) PGESTURECONFIG pGestureConfig,
                                                        // pointer to buffer to receive the returned array of GESTURECONFIG structures
    __in UINT cbSize);                                  // sizeof(GESTURECONFIG)
 
 
 
#endif /* WINVER >= 0x0601 */
 
#if(WINVER >= 0x0601)
 
/*
 * GetSystemMetrics(SM_DIGITIZER) flag values
 */
#define NID_INTEGRATED_TOUCH  0x00000001
#define NID_EXTERNAL_TOUCH    0x00000002
#define NID_INTEGRATED_PEN    0x00000004
#define NID_EXTERNAL_PEN      0x00000008
#define NID_MULTI_INPUT       0x00000040
#define NID_READY             0x00000080
 
#endif /* WINVER >= 0x0601 */
 
 
 
cwnd类中有一些东东值得挖掘:
 
// for touch:
 
/// <summary>
/// Register/Unregister window Windows touch support</summary>
/// <returns> 
/// TRUE if succeeds; otherwise FALSE.</returns>
/// <param name="bRegister">TRUE - register Windows touch support; FALSE - otherwise.</param>
/// <param name="ulFlags">A set of bit flags that specify optional modifications. This field may contain 0 or one of the following values: TWF_FINETOUCH; TWF_WANTPALM</param>
BOOL RegisterTouchWindow(BOOL bRegister = TRUE, ULONG ulFlags = 0);
 
/// <summary>
/// Specifies whether CWnd has touch support</summary>
/// <returns> 
/// TRUE if CWnd has touch support; otherwise FALSE.</returns>
BOOL IsTouchWindow() const;
 
// gesture:
#if (WINVER >= 0x0601)
/// <summary>
/// Set gesture touch paramaters</summary>
/// <returns> 
/// TRUE if succeeds; otherwise FALSE.</returns>
/// <param name="pConfig">Pointer to CGestureConfig. Cannot be NULL.</param>
BOOL SetGestureConfig(CGestureConfig* pConfig);
 
/// <summary>
/// Get gesture touch paramaters</summary>
/// <returns> 
/// TRUE if succeeds; otherwise FALSE.</returns>
/// <param name="pConfig">Pointer to CGestureConfig. Cannot be NULL.</param>
BOOL GetGestureConfig(CGestureConfig* pConfig);
 
/// <summary>
/// Returns the current gesture information (PGESTUREINFO)</summary>
/// <returns> 
/// Pointer to the current gesture info.</returns>
const PGESTUREINFO GetCurrentGestureInfo() const
{
return m_pCurrentGestureInfo;
}
#endif
 
 
 
// for touch:
BOOL m_bIsTouchWindowRegistered;
/// <summary>
/// Process inputs from Windows touch</summary>
/// <returns> 
/// TRUE if application processes Windows touch inputs; otherwise FALSE.</returns>
/// <param name="nInputsCount">total number of Windows touch inputs.</param>
/// <param name="pInputs">array of TOUCHINPUT.</param>
virtual BOOL OnTouchInputs(UINT nInputsCount, PTOUCHINPUT pInputs);
 
/// <summary>
/// Process single input from Windows touch</summary>
/// <returns> 
/// TRUE if application processes Windows touch input; otherwise FALSE.</returns>
/// <param name="pt">point where screen has been tocuhed (in the client coordinates).</param>
/// <param name="nInputNumber">number of touch input.</param>
/// <param name="nInputsCount">total number of touch inputs.</param>
/// <param name="pInput">pointer to TOUCHINPUT structure.</param>
virtual BOOL OnTouchInput(CPoint pt, int nInputNumber, int nInputsCount, PTOUCHINPUT pInput);
 
/// <summary>
/// The methods is called when the system asks a window which system gestures it would like to receive</summary>
/// <returns> 
/// A value indicating which system gestures the window would like to receive (TABLET_* flags, see WM_TABLET_QUERYSYSTEMGESTURESTATUS message).</returns>
/// <param name="ptTouch">point where screen has been tocuhed (in the client coordinates).</param>
virtual ULONG GetGestureStatus(CPoint ptTouch);
 
// for gesture:
CPoint m_ptGestureFrom;
ULONGLONG m_ulGestureArg;
BOOL m_bGestureInited;
PGESTUREINFO m_pCurrentGestureInfo;
 
/// <summary>
/// The method is called upon gesture zoom event</summary>
/// <returns> 
/// TRUE if application processes this event; otherwise FALSE.</returns>
/// <param name="ptCenter">Zoom center point. In client coordinates</param>
/// <param name="lDelta">The distance from the center point. In pixels</param>
virtual BOOL OnGestureZoom(CPoint ptCenter, long lDelta);
 
/// <summary>
/// The method is called upon gesture pan event</summary>
/// <returns> 
/// TRUE if application processes this event; otherwise FALSE.</returns>
/// <param name="ptFrom">Pan starting point. In client coordinates</param>
/// <param name="ptTo">Pan current point. In client coordinates</param>
virtual BOOL OnGesturePan(CPoint ptFrom, CPoint ptTo);
 
/// <summary>
/// The method is called upon gesture rotate event</summary>
/// <returns> 
/// TRUE if application processes this event; otherwise FALSE.</returns>
/// <param name="ptCenter">Rotation center point. In client coordinates</param>
/// <param name="dblAngle">Rotation angle. In radians</param>
virtual BOOL OnGestureRotate(CPoint ptCenter, double dblAngle);
 
/// <summary>
/// The method is called upon gesture 2 finger tap event</summary>
/// <returns> 
/// TRUE if application processes this event; otherwise FALSE.</returns>
/// <param name="ptCenter">Center point between 2 fingers. In client coordinates</param>
virtual BOOL OnGestureTwoFingerTap(CPoint ptCenter);
 
/// <summary>
/// The method is called upon gesture press and tap event</summary>
/// <returns> 
/// TRUE if application processes this event; otherwise FALSE.</returns>
/// <param name="ptPress">"Pressed" point. In client coordinates</param>
/// <param name="lDelta">The distance from the "pressed" point. In pixels</param>
virtual BOOL OnGesturePressAndTap(CPoint ptPress, long lDelta);


### STM32电容触摸模块开发概述 STM32作为一款功能强大的微控制器,在嵌入式领域有着广泛的应用场景。对于电容触摸按键的功能实现,可以通过硬件与软件相结合的方式完成。以下是关于STM32电容触摸模块的相关资料和教程总结。 #### 1. 常见的电容触摸方案 在实际应用中,常见的电容触摸控制器包括XPT2046、ADS7843等设备,这些外设通过SPI或其他接口与STM32通信,能够提供可靠的触控数据传输能力[^1]。然而,如果采用纯软件方法,则无需额外的硬件支持即可实现简单的电容触摸检测逻辑。 #### 2. 软件实现原理 电容触摸的核心在于利用寄生电容的变化来判断是否有物体接近或接触传感器区域。具体来说,当手指靠近金属板时会改变该处的有效电容量大小,从而影响RC充放电路的时间常数T=RC。因此,我们可以通过测量这一时间参数并将其转化为数字信号来进行处理分析[^4]。 为了提高精度以及抗干扰性能,在程序设计上通常采取如下措施之一: - **定时器法**:设置一个固定频率周期性的触发事件去读取当前状态; - **轮询机制**:不断循环查询直到满足条件为止; 无论哪种方式都需要考虑环境噪声等因素可能带来的误判情况,并适当增加阈值范围以减少错误率的发生概率。 #### 3. HAL库基础支持 针对初者而言,《STM32系列习笔记》提供了详尽的基础教内容覆盖了从认识单片机到高级特性等个方面知识点的习路径指导说明文档集合[^2] 。其中包含了如何配置基本外设如GPIO初始化设定过程描述等相关章节介绍部分特别适合新手入门阶段快速掌握操作技巧要点所在之处值得深入研究探讨一番才行呢! 另外还有专门讨论有关于"基于stm32实现电容触摸按键(初步)"[^3]"的文章可供参考阅读理解进一步加深印象巩固记忆效果更好些哦~ --- ### 示例代码片段展示 下面给出一段简易版伪码用于演示目的仅限于此: ```c #include "stm32f1xx_hal.h" #define TOUCH_PIN GPIO_PIN_x // 定义使用的IO引脚号 #define CHARGE_TIME_LIMIT 50 // 设定最大允许充电时限值(单位us) uint32_t measure_charge_time(void){ uint32_t count = 0; /* 配置TOUCH_PIN为输入模式 */ __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.Pin = TOUCH_PIN ; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; HAL_GPIO_Init(GPIOA,&GPIO_InitStruct); while(HAL_GPIO_ReadPin(GPIOA,TOUCH_PIN)==RESET && count<CHARGE_TIME_LIMIT){ count++; delay_us(1); // 微秒级延时函数需自行定义实现 } return count; } int main(){ if(measure_charge_time()>=(CHARGE_TIME_LIMIT*1.2)){ // 执行相应动作比如点亮LED灯泡之类的... } } ``` 上述例子展示了最基本的思路框架结构形式而已实际上还需要更细节方面的调整优化才能达到理想中的稳定运行状况水平线上下波动幅度较小的情况下也能正常工作不受外界因素太的影响制约作用力强弱程度不同所产生的差异表现出来等等诸方面都得考虑到才行啊亲们!!! ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值