http://jnative.free.fr/SPIP-v1-8-3/article.php3?id_article=4
public class JnativeRect extends AbstractBasicData<JnativeRect>{
protected JnativeRect(JnativeRect lValue) throws NativeException {
super(null);
createPointer();
mValue = this;
}
public int left;
public int top;
public int right;
public int bottom;
@Override
public JnativeRect getValueFromPointer() throws NativeException {
// TODO Auto-generated method stub
return null;
}
@Override
public int getSizeOf() {
return 4*4;
}
@Override
public Pointer createPointer() throws NativeException {
pointer = new Pointer(MemoryBlockFactory.createMemoryBlock(getSizeOf()));
return pointer;
}
}
public class Demo {
public static void main(String[] args) {
test();
}
public static void test(){
Display dis = new Display();
Shell shell = new Shell(dis,SWT.DIALOG_TRIM|SWT.RESIZE);
shell.setSize(800,600);
shell.setLayout(new FillLayout());
shell.setText("S2 Graph from SWT");
shell.open();
dosomething(shell);
while(!shell.isDisposed()){
if(!dis.readAndDispatch()){
dis.sleep();
}
}
dis.dispose();
}
private static void dosomething(Shell shell) {
try {
HWND hWnd = User32.FindWindow(null,"S2 Graph from SWT");
//m_hPE = PEcreate(PECONTROL_SGRAPH, WS_VISIBLE, &rect, hWnd, 1001);
System.loadLibrary("pegrp32c");// InterfaceFun是dll文件
// 參數說明InterfaceFun dll名,AddZhiYe函數名
JNative jnative = new JNative("pegrp32c", "PEcreate");
// 設置此函數的返回值
int i = 0;
// 賦予參數值
jnative.setParameter(i++,300);
jnative.setParameter(i++,org.xvolks.jnative.util.constants.winuser.WindowsConstants.WS_VISIBLE);
JnativeRect jr = new JnativeRect(null);
jr.getPointer().setIntAt(0, shell.getLocation().x);
jr.getPointer().setIntAt(4, shell.getLocation().y);
jr.getPointer().setIntAt(8, shell.getLocation().x+400);
jr.getPointer().setIntAt(12, shell.getLocation().y+400);
jnative.setParameter(i++,jr.getPointer());
jnative.setParameter(i++,shell.handle);
jnative.setParameter(i++,1001);
// 函數執行
jnative.invoke();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class JnativeRect extends AbstractBasicData<JnativeRect>{
protected JnativeRect(JnativeRect lValue) throws NativeException {
super(null);
createPointer();
mValue = this;
}
public int left;
public int top;
public int right;
public int bottom;
@Override
public JnativeRect getValueFromPointer() throws NativeException {
// TODO Auto-generated method stub
return null;
}
@Override
public int getSizeOf() {
return 4*4;
}
@Override
public Pointer createPointer() throws NativeException {
pointer = new Pointer(MemoryBlockFactory.createMemoryBlock(getSizeOf()));
return pointer;
}
}
public class Demo {
public static void main(String[] args) {
test();
}
public static void test(){
Display dis = new Display();
Shell shell = new Shell(dis,SWT.DIALOG_TRIM|SWT.RESIZE);
shell.setSize(800,600);
shell.setLayout(new FillLayout());
shell.setText("S2 Graph from SWT");
shell.open();
dosomething(shell);
while(!shell.isDisposed()){
if(!dis.readAndDispatch()){
dis.sleep();
}
}
dis.dispose();
}
private static void dosomething(Shell shell) {
try {
HWND hWnd = User32.FindWindow(null,"S2 Graph from SWT");
//m_hPE = PEcreate(PECONTROL_SGRAPH, WS_VISIBLE, &rect, hWnd, 1001);
System.loadLibrary("pegrp32c");// InterfaceFun是dll文件
// 參數說明InterfaceFun dll名,AddZhiYe函數名
JNative jnative = new JNative("pegrp32c", "PEcreate");
// 設置此函數的返回值
int i = 0;
// 賦予參數值
jnative.setParameter(i++,300);
jnative.setParameter(i++,org.xvolks.jnative.util.constants.winuser.WindowsConstants.WS_VISIBLE);
JnativeRect jr = new JnativeRect(null);
jr.getPointer().setIntAt(0, shell.getLocation().x);
jr.getPointer().setIntAt(4, shell.getLocation().y);
jr.getPointer().setIntAt(8, shell.getLocation().x+400);
jr.getPointer().setIntAt(12, shell.getLocation().y+400);
jnative.setParameter(i++,jr.getPointer());
jnative.setParameter(i++,shell.handle);
jnative.setParameter(i++,1001);
// 函數執行
jnative.invoke();
} catch (Exception e) {
e.printStackTrace();
}
}
}