【发布时间】:2017-03-22 05:06:45
【问题描述】:
在 Windows 窗体控件中,我已使用 SetGestureConfig 方法正确配置了触摸手势。它正确配置了控件的触摸手势。在某些情况下,我需要检查控件是否正确启用了特定的触摸手势。我尝试使用 GetGestureConfig 方法来检查特定手势是否启用。但是这个方法总是 返回错误值。我还尝试使用 GetLastError() 方法 来获取错误消息,但它总是返回 value 0。请在下面找到代码,
int gestureConfigSize = Marshal.SizeOf(new GESTURECONFIG());
GESTURECONFIG gc = new GESTURECONFIG();
gc.dwID = 0;
gc.dwWant = WindowMessages.GC_ALLGESTURES;
gc.dwBlock = 0;
if (SetGestureConfig(control.Handle, 0, 1, ref gc, gestureConfigSize))
MessageBox.Show("Zoom gesture configured properly");
GESTURECONFIG gc1 = new GESTURECONFIG();
gc1.dwID = 0;
gc1.dwWant = WindowMessages.GC_ALLGESTURES;
gc1.dwBlock = 0;
GESTURECONFIG[] gestures = new GESTURECONFIG[] { gc1 };
bool value = GetGestureConfig(control.Handle, 0, 0, 1, gestures, gestureConfigSize);
if (!value)
{
int errorValue = GetLastError();
}
请在下面找到 Dll 导入代码,
[DllImport("Kernel32.dll")]
static extern Int32 GetLastError();
[DllImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetGestureConfig(IntPtr hWnd, int dwReserved, int cIDs, [In] [Out] GESTURECONFIG[] pGestureConfig, int cbSize);
[DllImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetGestureConfig(IntPtr hWnd, int dwReserved, int cIDs, ref GESTURECONFIG pGestureConfig, int cbSize);
[DllImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetGestureConfig(IntPtr hWnd, int dwReserved, int flags, int cIDs, [In] [Out] GESTURECONFIG[] pGestureConfig, int cbSize);
请建议如何使用 GetGestureConfig 方法检查控件是否启用了触摸手势。
谢谢。
【问题讨论】:
标签: c# winforms touch gestures gesture-recognition