如何在Mac 64位可可环境中获取SWT控件的句柄? [英] How to get the handle of SWT control in Mac 64 bit cocoa enviornment?

查看:129
本文介绍了如何在Mac 64位可可环境中获取SWT控件的句柄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于Eclipse的RCP应用程序,我需要将SWT控件句柄传递给本机代码以在其上绘制内容. 我有以下代码来获取任何SWT控件的句柄:

I have one Eclipse based RCP application in which I need to pass the SWT Control handles to native code to paint something on it. I have the following code to get the handle of any SWT control:

public static int getControlHandle(Control c){
            int handle = 0;
            try {
                if(_isMACOS){
                    if(_viewField== null)
                        _viewField = Control.class.getDeclaredField("view");
                    Object view = _viewField.get(c);
                    if(_idField== null) {
                        Class<?>idClass = Class.forName("org.eclipse.swt.internal.cocoa.id");
                        _idField = idClass.getDeclaredField("id");
                    }
                    handle = _idField.getInt(view);

                }
                else {
                    if(_idField== null)
                        _idField = Control.class.getDeclaredField("handle");
                    handle = _idField.getInt(c);
                }
            }
            catch(Exception e){

            }
            return handle;
    }

_viewField_idFieldjava.lang.reflect.Field.

尽管此方法在Windows和Mac 32位操作系统上运行良好,但不适用于Mac 64位可可库和env. 获取64位Mac手柄的方式是否有任何变化?

While this works well for Windows and Mac 32 bit but its not working with Mac 64 bit cocoa libs and env. Is there any change in the way to get the handle for 64 bit Mac?

推荐答案

在可可粉64位上,id值是long而不是int

On Cocoa 64 bit the id value is a long not an int

这篇关于如何在Mac 64位可可环境中获取SWT控件的句柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆