It would be a great improvement if a native Window handle of a JFrame could be provided. This is needed in order to "embed" a JFrame or a Window into a WindowsForms Application.
Eaxample:
In a WindowsForms Application we can easily set the parent with an dll import:
[DllImport("user32.dll")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
Thus we neet a handle from the frame, in pure Java it could be done like this:
import sun.awt.windows.WComponentPeer;
public static long getHWnd(Frame f) {
return f.getPeer() != null ? ((WComponentPeer) f.getPeer()).getHWnd() : 0;
}
Unfortunately, there's no WComponentPeer in ikvm. Please provide at least a WComponentPeer or an utility class to get the native window handle of JFrame.
With the follow code you receive the instance of System.Windows.Forms.Form of the JFrame and print the handle.
public delegate void invokeForm(System.Windows.Forms.Form form);
static void Main(string[] args)
{
javax.swing.JFrame frame = new javax.swing.JFrame("My Frame");
frame.pack();
frame.setVisible(true);
java.awt.peer.ComponentPeer peer = frame.getPeer();
Type peerType = peer.GetType();
System.Reflection.MethodInfo getControl = peerType.GetMethod("get_Control", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
System.Windows.Forms.Form form = (System.Windows.Forms.Form)getControl.Invoke(peer, null);
form.Invoke(new invokeForm(WriteLineHandle), form);
}
static void WriteLineHandle(System.Windows.Forms.Form form)
{
Console.WriteLine(form.Handle);
}