【问题标题】:How to get WM_TOUCH messages in a message-only window如何在仅消息窗口中获取 WM_TOUCH 消息
【发布时间】:2012-05-23 13:55:37
【问题描述】:

我刚刚开始了一个项目,我想从触摸屏接收所有触摸事件来处理它们,无论是哪个活动窗口。我正在使用带有 C++ 的 Win32 API(我是 Win32 编程的新手)。我想使用仅消息窗口,但我没有成功获得 WM_TOUCH 消息(尽管我认为它是为触摸事件正确创建和注册的)。这是我初始化消息窗口的函数。

HWND InitMessageOnlyWindow(HINSTANCE hInstance, int nCmdShow) {
    LPWSTR szWindowClassName = TEXT("msgOnly");

    WNDCLASSEX windowClass;
    memset(&windowClass, 0, sizeof(windowClass));
    windowClass.cbSize = sizeof(windowClass);
    windowClass.lpfnWndProc    = WndProc;
    windowClass.lpszClassName  = szWindowClassName;
    if(RegisterClassEx(&windowClass)==0) {
    std::cerr << "RegisterClass" << std::endl;
    return 0;
    }

    HWND hWindow = CreateWindow(
    szWindowClassName,
    L"",
    0,
    0, 0, 0, 0,
    HWND_MESSAGE,
    0, 0, 0);
    if (!hWindow) {
    std::cerr << "CreateWindow" << std::endl;
    return 0;
    }

    if(RegisterTouchWindow(hWindow, 0)==0) {
    std::cerr << "RegisterTouchWindow" << std::endl;
    return 0;
    }

    return hWindow;
}

我已经测试了以下内容:

  • 要在仅消息窗口中获取 WM_INPUT 消息,它可以工作。
  • 要在经典窗口中获取 WM_TOUCH 消息,它可以工作。

根据这个post,消息窗口需要处于活动状态。我试了一下,结果很奇怪,SetActiveWindow返回NULL(所以应该有问题)但是GetLastError不持有。这不会使我的程序正常工作。我还没有深入研究钩子的事情,我想先知道为什么这不起作用。

谢谢。

【问题讨论】:

  • 呃,触摸事件进入只能激活的窗口。来自MSDNAfter the application registers its window, notifications from the Windows Touch driver are forwarded to the application when input is made on the window.After the first touch message is received on a window, all touch messages are sent to that window until another window receives focus.
  • 感谢您指出这一点。实际上,您可以设置一个仅消息窗口处于活动状态(使用 SetActiveWindow),它会接收所有预期的消息,因此会造成混淆。但实际上我已经意识到触摸输入事件和仅消息窗口不兼容。

标签: windows winapi input touch


【解决方案1】:

使用follow code,可以注册所有调用wm_touch hook dll的窗口。 function.so 您可以捕获 Wm_TOUCH 消息。 RegisterTouchWindow(((PCWPSTRUCT)lParam)->hwnd,0);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 1970-01-01
    相关资源
    最近更新 更多