How can I check the touch gestures is enabled for the control or not?
Asked Answered
R

1

6

In windows forms control, I have properly configured the touch gesture by using the SetGestureConfig method. It properly configured the touch gesture for the control. For some cases I need to check whether the control is properly enabled the particular touch gesture or not. I try to use the GetGestureConfig method, to check the particular gesture is enabled or not. But this method always returns false value alone. And also I try to get the error message by using the GetLastError() method, but it is always returns the value 0. Please find the code below,

        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();
        }

And please find the Dll import codes below,

    [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);

Please suggest how to check the touch gesture is enabled for the control or not by using the GetGestureConfig method.

Thanks.

Robber answered 22/3, 2017 at 5:6 Comment(0)
K
0
  1. You shouldn't [DllImport] GetLastError yourself in managed code, call Marshal.GetLastError (see https://blogs.msdn.microsoft.com/adam_nathan/2003/04/25/getlasterror-and-managed-code/) for more details.
  2. For this to work, you need to set the SetLastError=true flag in your [DllImport] to ensure that the error is captured.
Klausenburg answered 11/6, 2018 at 4:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.