简体   繁体   English

在Eclipse RCP中处理自定义设备事件

[英]Process custom device event in Eclipse RCP

I have an Eclipse RCP product working well with keyboard and mouse. 我有一个Eclipse RCP产品可以很好地与键盘和鼠标配合使用。 I want to support a custom hardware in my product. 我想在我的产品中支持自定义硬件。 To enable the device in the Eclipse RCP product, I have written JNI code. 为了在Eclipse RCP产品中启用该设备,我编写了JNI代码。 This JNI code initializes the device & driver (which is working correctly). 此JNI代码初始化设备和驱动程序(运行正常)。 After calling this JNI method the RCP application code starts receiving the events in Display.readAndDispatch() method. 调用此JNI方法后,RCP应用程序代码开始在Display.readAndDispatch()方法中接收事件。 What I don't understand is, how to get this events to my widget class. 我不明白的是,如何使此事件进入我的小部件类。 All SWT widgets have windowProc methods which handles the events. 所有SWT小部件都具有处理事件的windowProc方法。 These methods only handles predefined events and they are private (package private) methods, so I can't event override them. 这些方法仅处理预定义的事件,它们是私有(程序包私有)方法,因此我无法进行事件覆盖。

At http://www.eclipse.org/articles/Article-Writing%20Your%20Own%20Widget/Writing%20Your%20Own%20Widget.htm page, in native widget section, they explained about adding a hook to windowProc method in the C++ code. http://www.eclipse.org/articles/Article-Writing%20Your%20Own%20Widget/Writing%20Your%20Own%20Widget.htm页面上,在本机窗口小部件部分,他们解释了如何在C ++代码。 I tried doing that in following way: 我尝试通过以下方式进行操作:

JNIEXPORT jint JNICALL Java_com_aiit_iadss_framework_event_SpaceMouseEventManager_initInternal
    (JNIEnv *env, jobject obj, jlong hwnd ) 
{
        fprintf(stderr, "Initializing the space mouse module!");

        //code to init the device & driver

        if( res > 0 )
        {
            //the initialization was successful. Setup the 3D mouse event listener
            WM_3DMOUSE = RegisterWindowMessage (_T("SpaceWareMessage00"));

            //adding hook on RCP application window for WindowProc
            oldProc = (WNDPROC) SetWindowLongPtr((HWND) hwnd, GWLP_WNDPROC, (long) WindowProc);
        }
        return res;
}

LRESULT CALLBACK WindowProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    int            num;      /* number of button returned */
    //SiSpwEvent     Event;    /* 3DxWare Event */ 
    //SiGetEventData EData;    /* 3DxWare Event Data */

    if( msg == WM_3DMOUSE )
    {
        fprintf( stderr, "Space mouse event caught!");
        return (TRUE);
    }
    //call windowproc to handle other events
    return CallWindowProc( oldProc, hwnd, msg, wParam, lParam );
}

When I run above code, the JVM crashes with access violation code. 当我运行上述代码时,JVM崩溃并显示访问冲突代码。 Can you please help me with solving the issue? 您能帮我解决问题吗?

Ok, I finally did this by adding the WindowProc handler in Java code as below: 好的,我最终通过在Java代码中添加WindowProc处理程序来完成此操作,如下所示:

Callback winprocCallback = new Callback( MyEventProcessingClass.class, "windowProc", 4 );
        MyEventProcessingClass.oldWinProc = OS.SetWindowLongPtr( shellHandle, OS.GWLP_WNDPROC,
                winprocCallback.getAddress() );

And the windowProc method is implemented as: 而且windowProc方法实现为:

public static long windowProc( long hwnd, long msg, long wparam, long lParam )
{
    if( msg == 'My device event id' )
    {
        //process it & return 1;
    }
    return OS.CallWindowProc( SpaceMouseServiceImpl.oldWinProc, hwnd, (int) msg, wparam, lParam );
}

This way I was able to process the custom event in my code. 这样,我就可以在代码中处理自定义事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM