0

アプリを Touch-Compliant にする必要があるため、最近 Windows Touch API に飛び込みました。

Windows API は私にとってまったく新しいものです。そのため、おそらく何かを見逃していました。

これが私の問題です。単純なジェスチャーアプリの Microsoft サンプルをダウンロードしました。うまく機能しますが、HWND の作成にバインドされている WinProc で処理されるジェスチャー機能が追加されます。問題は、私の「実際の」アプリケーションがそれ自体で HWND を作成することです。そのため、フックを使用して WM_TOUCH メッセージを受信したいと考えています。

スタンドアロンアプリでこのように試しました(実際のアプリのようにDLLは使用されていません)

//Window Parameters (Can't be modified in my original App)
//------Automatically called by an external lib in my "real app"------------
ATOM BaseApp_RegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style            = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc      = WndProc;
    wcex.cbClsExtra       = 0;
    wcex.cbWndExtra       = 0;
    wcex.hInstance        = hInstance;
    wcex.hIcon            = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MTGEST));
    wcex.hCursor          = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName     = MAKEINTRESOURCE(IDC_MTGEST);
    wcex.lpszClassName    = (LPSTR)g_wszWindowClass;
    wcex.hIconSm          = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassEx(&wcex);
}    
//------/Automatically called by an external lib in my "real app"------------

//Create the Window of the Basic App
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
    //------Automatically called by an external lib in my "real app"------------
    // (....)
    BaseApp_RegisterClass(hInstance);
    // (....)
    //------/Automatically called by an external lib in my "real app"------------

   //------This is what I can add to my "real app"------------
   //Register the Touch Window
   RegisterTouchWindow(hWnd, 0 );
   UpdateWindow(hWnd);

   unsigned long threadId = GetWindowThreadProcessId(hWnd, 0);
    //Hook the SENT Messages
    SetWindowsHookEx(
        WH_GETMESSAGE,
        (HOOKPROC) HookTouchSENT,
        NULL,
        threadId);  

    //Hook the POSTED Messages
   SetWindowsHookEx(
       WH_CALLWNDPROC,
       (HOOKPROC) HookTouchPOSTED,
       NULL,
       threadId);

   //------/This is what I can add to my "real app"------------
}

//------Automatically called by an external lib in my "real app"------------
//Primary WinProc of the Window (Can't be modified in my original App)
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    if(message == WM_TOUCH)LogInConsole("Caught a WM_TOUCH in the Main WndProc\n");   //WM_TOUCH is ALWAYS caught here when touch the screen
    else if(message == WM_GESTURE)LogInConsole("Caught a WM_GESTURE in the Main WndProc\n");

    return DefWindowProc(hWnd, message, wParam, lParam);
}
//------/Automatically called by an external lib in my "real app"------------

//------This is what I can add to my "real app"------------
//Get the 'POSTED' Messages of the Window
LRESULT CALLBACK HookTouchPOSTED(int nCode, WPARAM wParam, LPARAM lParam)  
{
    HWND hWnd = m_hwnd; 

    UINT message = ((PCWPSTRUCT)lParam)->message; 

    if(message == WM_TOUCH)LogInConsole("Caught a WM_TOUCH in HookTouchPOSTED\n");   //WM_TOUCH is NEVER caught here when touch the screen
    else if(message == WM_GESTURE)LogInConsole("Caught a WM_GESTURE in HookTouchPOSTED\n");   


    std::stringstream strStream; strStream<<"Received POSTED Message:"<<message<<", Hex:0x"<<std::hex<<((PCWPSTRUCT)lParam)->message<<std::endl;  //Receive the normals windows messages and although WM_GESTURENOTIFY
    LogInConsole(strStream.str());

    return CallNextHookEx(0,nCode, wParam, lParam);
}

//Get the 'SENT' Messages of the Window
LRESULT CALLBACK HookTouchSENT(int nCode, WPARAM wParam, LPARAM lParam) 
{

    HWND hWnd = m_hwnd; 

    UINT message = ((PCWPSTRUCT)lParam)->message; 

    if(message == WM_TOUCH)LogInConsole("Caught a WM_TOUCH in HookTouchPOSTED\n");   //WM_TOUCH is NEVER caught here when touch the screen
    else if(message == WM_GESTURE)LogInConsole("Caught a WM_GESTURE in HookTouchPOSTED\n");

    std::stringstream strStream; strStream<<"Received POSTED Message:"<<message<<", Hex:0x"<<std::hex<<((PCWPSTRUCT)lParam)->message<<std::endl;
    LogInConsole(strStream.str());

    return CallNextHookEx(0,nCode, wParam, lParam);
}    
//------/This is what I can add to my "real app"------------

私の問題は、WM_TOUCH メッセージがフックを通過することはなく、WinProc でのみ通過することです。実際、フックで WM_GESTURENOTIFY メッセージを受け取るだけで、ジェスチャが開始されたことを通知しますが、値を与える必要がある次の「WM_TOUCH」メッセージは決してキャッチされません...

誰かが以前にこの問題を抱えていましたか?

助けてくれてありがとう

4

1 に答える 1

1

助けてくれたレイモンドに感謝します。サブクラス化が解決策でした!最後に、すべてのフックを削除して、次のようにしました。

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
    //------Automatically called by an external lib in my "real app"------------
    // (....)
    BaseApp_RegisterClass(hInstance);
    // (....)
    //------/Automatically called by an external lib in my "real app"------------



   //------This is what I can add to my "real app"------------
   //Register the Touch Window
   RegisterTouchWindow(hWnd, 0 );   //If called then receive WM_TOUCH messages. Else receive WM_GESTURE messages

   //----SUBCLASS THE WINDOW
    UINT_PTR uIdSubclass;
    DWORD_PTR dwRefData;

   bool resultsc = SetWindowSubclass(
       hWnd,
       windowProcSubclass,
       uIdSubclass,
       dwRefData
       );
   if (resultsc) LogInConsole("Window Subclassed with success\n");
   //----/SUBCLASS THE WINDOW

   //------/This is what I can add to my "real app"------------
}

//------And the subclass Proc that now catches the WM_TOUCH and WM_GESTURE messages: ------------
LRESULT CALLBACK windowProcSubclass(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam,  UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{

    switch (message)
    {
    case WM_TOUCH:
        LogInConsole("CATCH A WM_TOUCH!!\n");
        break;
    case WM_GESTURENOTIFY:
        LogInConsole("WM_GESTURENOTIFY!!\n");
        break;      
    case WM_GESTURE:
        LogInConsole("CATCH A WM_GESTURE!!\n");        
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}
于 2013-03-29T09:21:42.633 に答える