在Windows 10上挂钩WM_TOUCH消息

时间:2018-06-20 23:11:49

标签: windows-10 c++builder setwindowshookex wm-touch

我试图创建一个钩子DLL来捕获WM_TOUCH消息,然后再将它们发送到Windows 10上的操作系统。但是,由于我没有触摸屏,因此只能使用鼠标的MultitouchVista touch。我认为这就是为什么在挂接过程中没有收到WM_TOUCH条消息的原因。

这真的是问题吗,还是Windows 10对触摸事件的处理不同?

这是我的DLL代码:

#include <vcl.h>
#include <windows.h>
#include "ClangCpp.h"

#pragma hdrstop
#pragma argsused

#define DLLEXPORT __declspec(dllexport) __stdcall

//---------------------------------------------------------------------------
//const ULONG TOUCH_FLAGS_2(/*TWF_FINETOUCH|*/TWF_WANTPALM);
TMemo *Logger = NULL;
HHOOK hTouchHook;
typedef DynamicArray<TTouchInput> TTouchInputs;
//---------------------------------------------------------------------------
//extern "C" __stdcall __declspec(dllexport)
LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    //Logger->Clear();
    //if (nCode < 0)
    //    return CallNextHookEx(0, nCode, wParam, lParam);

    if (nCode == HC_ACTION)
    {
    //  Logger->Lines->Add("HC_ACTION");
    //    Logger->Lines->Clear();
        LPMSLLHOOKSTRUCT msg = (LPMSLLHOOKSTRUCT)lParam;
    //    RegisterTouchWindow(msg->hwnd, 0);
        Logger->Lines->Add("Action: " + String(msg->dwExtraInfo ));

    //  switch (msg->message)
    //  {
    //      case WM_POINTERDOWN:
    //      case WM_POINTERUPDATE:
    //      case WM_POINTERUP:
    //          Logger->Lines->Add("WM_POINTER");
    //          POINTER_INFO pointerInfo = {};

    //          if (GetPointerInfo(GET_POINTERID_WPARAM(msg->wParam), &pointerInfo)) {
    //              POINT p = pointerInfo.ptPixelLocation;
    //
    //              Logger->Lines->Add(String(p.x) + " : " + String(p.y));
    //          }
    //          break;
    //  }

    //  if (msg->message == WM_TOUCH)
    //  {
    //      Logger->Lines->Add("WM_TOUCH");
    //      TTouchInputs TouchInputs;
    //      TouchInputs.Length = msg->wParam;
    //      Logger->Lines->Add(TouchInputs.Length);
    //
    //      if (TouchInputs.Length > 0)
    //      {
    //          if (GetTouchInputInfo((HTOUCHINPUT)msg->lParam, msg->wParam, &TouchInputs[0], sizeof(TTouchInput)))
    //          {
    //              for (int i = 0; i < TouchInputs.Length; ++i)
    //              {
    //                  Logger->Lines->Add(TouchInputs[i].dwID);
    //                  if (Inpt->dwID % 2)
    //                  {
    //                      return 1;
    //                  }
    //              }
    //          }
    //          CloseTouchInputHandle((HTOUCHINPUT)msg->lParam);
    //      }
    //  }
    }

    return CallNextHookEx(NULL, nCode, wParam, lParam);
}
//---------------------------------------------------------------------------
extern "C" __stdcall __declspec(dllexport) void SetControl(TMemo* aLogger)
{
    Logger = aLogger;
}
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
    switch (reason)
    {
    case DLL_PROCESS_ATTACH:
        hTouchHook = SetWindowsHookEx(WH_MOUSE_LL,GetMsgProc, hinst, 0);
        break;
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
        break;
    case DLL_PROCESS_DETACH:
        UnhookWindowsHookEx(hTouchHook);
        break;
    }
    return 1;
}

0 个答案:

没有答案