Xojo WndProc callback example?

Does anyone have a simple example for using the procedure WndProc callback in Xojo? I have written a win32 program in C++ on Windows that works well with gestures, and I can’t seem to figure out how to initiate the callback to determine the gestures recorded from touching the screen.

If someone has a simple example program (doesn’t need to include gesture commands), then I can convert the C++ code to Xojo.

Here is an example of the C++ code.

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId;
    PAINTSTRUCT ps;
    HDC hdc;

    switch (message)
    {
    case WM_GESTURENOTIFY:
        {
        OutputDebugStringA("WM_GESTURENOTIFY\n");
            GESTURECONFIG gc = {
                0,              // gesture ID
                GC_ALLGESTURES, // settings related to gesture ID that are to be 
                                // turned on
                0               // settings related to gesture ID that are to be 
                                // turned off
            };
            BOOL bResult = SetGestureConfig(
                hWnd,                 // window for which configuration is specified  
                0,                    // reserved, must be 0
                1,                    // count of GESTURECONFIG structures
                &gc,                  // array of GESTURECONFIG structures, dwIDs will be processed in the
                                      // order specified and repeated occurances will overwrite previous ones
                sizeof(GESTURECONFIG) // sizeof(GESTURECONFIG)
            );                        
            
            if (!bResult)
            {
                ASSERT(L"Error in execution of SetGestureConfig" && 0);
            }
        }
        break;

    case WM_GESTURE:
        OutputDebugStringA("WM_GESTURE\n");
        return g_cGestureEngine.WndProc(hWnd,wParam,lParam);
        break;
    case WM_SIZE:
        OutputDebugStringA("WM_SIZE\n");
        g_cRect.ResetObject(LOWORD(lParam),HIWORD(lParam));
        break;

    case WM_COMMAND:
        OutputDebugStringA("WM_COMMAND\n");
        wmId = LOWORD(wParam);
         switch (wmId)
        {
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_PAINT:
         hdc = BeginPaint(hWnd, &ps);       
         g_cRect.Paint(hdc);
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        OutputDebugStringA("DESTROY\n");
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

Thanks for your help.

Hi Eugene.

If you have the MBS plugins there are functions that allow you to intercept the Windows messages.

We have some code in our app that uses WndProcs but it might be next week before I could get it into a form you could use (think it was based on Aaron Ballmans Windows Functionality Suite).

For MBS - take a look at WinNotificationMBS. There is also WinPointerEventsMBS.

Patching the WndProc for a Xojo window is an easy way to crash Xojo applications.

Well, with WinGestureConfigMBS class, we do have this in our plugins.
Thanks @kevin_g for mentioning this.

But I fear Eugen may want to write a book and looks for a way to do this via declares?
e.g. declare to SetWindowLong and then get old ptr into a delegate, then setting new method to replace it and don’t forget to call old one from there. Not sure if this is doable in Xojo.

Yeh, you can do it all in Xojo. We’ve had WndProcs for owner draw menus + other things for over 10 years.

2 Likes

The Windows Functionality Suite has code for this:

5 Likes

Thank you Kevin. I am not in a rush, a waiting a week or two is perfectly fine. I read Windows Functionality Suite and couldn’t quite figure it out - and am still trying :slight_smile:

Hi Christian. Yes, I have had recent requests for this and would like to help them out. I can create a plugin, and this is would not be fair to you, since you are the plugin guru. I’ll just write my declares for my book, this way there isn’t conflict. :slight_smile:

Thanks Andrew. As always, you are a wealth of knowledge. I’ll try the code again and see if I can get a simple example running in Xojo. :slight_smile: