问题
I've got a Java application that uses SWT as its widget toolkit.
I've also got a Windows C# application.
I'd like a way to draw an SWT Composite into this C# application.
I can think of two ways to do this:
Handles: Since SWT is based on the native windowing toolkit, it seems like there should be a way to create a Composite in the C# application, pass the native pointer to the Java application, and then control the Composite from there.
OLE: Since SWT can definitely consume OLE components, maybe there's also a way for it to present itself as an OLE component?
Anybody have any tips on how I can accomplish this? I'm not afraid of complicated communication between the Java and C# on startup, but I'm really hoping to be able to control the Composite from Java seamlessly once it is set up.
回答1:
To put your SWT composite inside your winform you can start the SWT application in new process and then use Process.MainWindowHandle to get the child process window handle.
This article provide an example to composite another process.
This link is a specific solution for SWT inside winform and winform inside winform(change the process to start...).
In the solution I also demonstrate a way to communicate between the processes through the std-in/out.(there are a lot of questions about it)
Hint: The code in the repository is not a production code! (C# and Java)
I just want to provide a demo. when i have time, i will refactor the code...
来源:https://stackoverflow.com/questions/28639592/embed-swt-composite-into-c-sharp-application