我必须开发一个C#应用程序,它需要使用高级手势来改善用户体验。为了做到这一点,我需要获取信息 当用户调用某个手势时。
因为WndProc是.NET CE中的一个禁忌,我使用OpenNETCE的Application2和IMessageFilter类来接收WM流量。
在我的MessageFilter中,我查找WM_GESTURE消息以及那里的消息 我被卡住了。
我只是通过调用此函数来获得任何有意义的结果:
https://msdn.microsoft.com/en-us/library/ee503217.aspx
public class InitiateServiceBus : ServiceControl
{
IBusControl _busControl;
public bool Start(HostControl hostControl)
{
_busControl = Bus.Factory.CreateUsingRabbitMq(x =>
{
IRabbitMqHost host = x.Host(new Uri("rabbitmq://localhost"), h =>
{
h.Username("guest");
h.Password("guest");
});
x.ReceiveEndpoint(host, "request_service",
e =>
{
e.Consumer<RequestConsumer>();
});
});
_busControl.Start();
return true;
}
public bool Stop(HostControl hostControl)
{
_busControl.Stop();
return true;
}
}
public class RequestConsumer : IConsumer<ISimpleRequest>
{
private readonly ILog _log = Logger.Get<RequestConsumer>();
public async Task Consume(ConsumeContext<ISimpleRequest> context)
{
_log.InfoFormat("I am consumer {0}", context.Message.CustomerId);
Thread.Sleep(TimeSpan.FromSeconds(30));
context.Respond(new SimpleResponse
{
CusomerName = "Processing Finished "
});
}
private class SimpleResponse :ISimpleResponse
{
public string CusomerName { get; set; }
}
}
以下是相关代码:
BOOL GetGestureInfo(
HGESTUREINFO hGestureInfo
PGESTUREINFO pGestureInfo
);
它总是给我错误代码87。
public class TestMessageFilter : IMessageFilter
{
[DllImport("coredll", SetLastError = true)]
public static extern bool GetGestureInfo(IntPtr hGesture, ref GESTUREINFO lGesture);
public static uint WM_GESTURE = 0x0119;
public bool PreFilterMessage(ref Microsoft.WindowsCE.Forms.Message m)
{
// ...
if (m.Msg == WM_GESTURE)
{
GESTUREINFO gi = new GESTUREINFO() {
cbSize = (uint)Marshal.SizeOf(typeof(GESTUREINFO))
};
bool success = GetGestureInfo(m.LParam, ref gi);
if (success)
{
// ...
}
else
{
int x = Marshal.GetLastWin32Error(); // => 87
}
}
// ...
}
[StructLayout(LayoutKind.Sequential)]
public struct POINTS
{
public short x;
public short y;
}
[StructLayout(LayoutKind.Sequential)]
public struct GESTUREINFO
{
public UInt32 cbSize;
public UInt32 dwFlags;
public UInt32 dwID;
public IntPtr hwndTarget;
public POINTS ptsLocation;
public UInt32 dwInstanceID;
public UInt32 dwSequenceID;
public UInt64 ullArguments;
public UInt32 cbExtraArguments;
}
}
为什么不起作用? 什么无效? 它让我疯了......
很多,非常感谢提前。
编辑: 我发现这篇帖子on the msdn forums使用的是IntPtr而不是 对GestureInfo的引用作为第二个参数。
ERROR_INVALID_PARAMETER
但它为我带来了相同的ERROR_INVALID_PARAMETER错误。
没有人有解决方案或其他方法从C#获取GestureInfo吗?
答案 0 :(得分:1)
我只有Windows Embedded Compact 7的经验,但与2013年相比应该没有太大差异 - 您是否先启用了手势? (你可能已经做过了,因为你正在接收WM_GESTURE,但无论如何都是代码):
[DllImport(User32Library)]
public static extern bool EnableGestures(IntPtr hWnd, GestureMask flags, uint scope);
[Flags]
public enum GestureMask : ulong
{
TGF_GID_PAN = 0x10,
TGF_GID_SCROLL = 0x100,
TGF_GID_HOLD = 0x200,
TGF_GID_SELECT = 0x400,
TGF_GID_DOUBLESELECT = 0x800,
TGF_GID_DIRECTMANIPULATION = 0x1000,
TGF_GID_ALL = TGF_GID_PAN | TGF_GID_SCROLL | TGF_GID_HOLD | TGF_GID_SELECT | TGF_GID_DOUBLESELECT,// | TGF_GID_DIRECTMANIPULATION,
}
我选择复制粘贴我们的工作示例;我不记得TGF_GID_DIRECTMANIPULATION是否为了方便起见而被排除在TGF_GID_ALL之外,还是因为我们遇到了问题,抱歉
bool enabled = EnableGestures(Handle, Native.GestureMask.TGF_GID_ALL, 0);
GetGestureInfo的以下签名适用于我们的设备:
[DllImport("coredll.dll")]
public static extern bool GetGestureInfo(IntPtr hGestureInfo, ref GestureInfo pGestureInfo);
使用结构GestureInfo:
[StructLayout(LayoutKind.Sequential)]
public struct GestureInfo
{
/// <summary>
/// Specifies the size of the structure in bytes. This must be set to Marshal.SizeOf(typeof(GESTUREINFO))
/// </summary>
public uint Size;
/// <summary>
/// Gesture Flags
/// </summary>
public GestureState State;
/// <summary>
/// Gesture Id
/// </summary>
public GestureKind Kind;
/// <summary>
/// HWND of the target winndow
/// </summary>
public IntPtr TargetWindow;
/// <summary>
/// Coordinates of start of gesture
/// </summary>
public short LocationX;
/// <summary>
/// Coordinates of start of gesture
/// </summary>
public short LocationY;
/// <summary>
/// Gesture Instance Id
/// </summary>
public uint InstanceId;
/// <summary>
/// Gesture Sequence Id
/// </summary>
public uint SequenceId;
/// <summary>
/// Arguments specific to gesture
/// </summary>
public ulong Arguments;
/// <summary>
/// Size of extra arguments in bytes
/// </summary>
public uint ExtraArguments;
}
GestureState:
[Flags]
public enum GestureState : uint
{
/// <summary>
/// The gesture has no associated state
/// </summary>
None = 0,
/// <summary>
/// The gesture is the beginning of pan gesture
/// </summary>
Begin = 1,
/// <summary>
/// The gesture is the end of a pan gesture that will transition into a scroll gesture
/// </summary>
Inertia = 2,
/// <summary>
/// The gesture is the end of a pan gesture
/// </summary>
End = 4
}
和GestureKind:
/// <summary>
/// The kind of gesture.
/// </summary>
public enum GestureKind : uint
{
/// <summary>
/// The beginning of a gesture operation.
/// </summary>
Begin = 1,
/// <summary>
/// The end of a gesture operation.
/// </summary>
End = 2,
/// <summary>
/// A pan gesture.
/// </summary>
Pan = 4,
/// <summary>
/// A scroll gesture.
/// </summary>
Scroll = 8,
/// <summary>
/// A hold gesture.
/// </summary>
Hold = 9,
/// <summary>
/// A select gesture.
/// </summary>
Select = 10,
/// <summary>
/// A double-select gesture.
/// </summary>
DoubleSelect = 11,
/// <summary>
/// Direct manipulation.
/// </summary>
DirectManipulation = 12,
}
调用方法的代码:
GestureInfo gesture = new GestureInfo();
gesture.Size = (uint)Marshal.SizeOf(typeof(GestureInfo));
bool result = GetGestureInfo(lParam, ref gesture);
我和你的第一次尝试之间没有太大区别;在MSDN示例中唯一突出的是硬编码大小为48(可能意味着读取任何ExtraArguments)。
我们 选择设置自定义窗口程序 - 但我不明白为什么这种差异很重要。