1 Reply Latest reply on Mar 6, 2010 3:15 PM by 843807

    about jni and mfc: how to attach a mfc dialog/window to the hwnd from jni

      Our Company has a MFC application, now we want to immigrate it to java little by little, so we want to use JNI to adapter.
      I've create a java application and a jni MFC dll, see below:
      In Java Application:
      +public class DialogInJava extends Canvas {+
      +static {+
      +{color:#0000ff}*public native void paint(Graphics g);*{color}+
      +public void ShowDialog()+
      +Frame f = new Frame();+
      +f.setBounds(0, 0, 400, 300);+
      +f.add( this );+
      +public static void main(String [] args)+
      +DialogInJava obj = new DialogInJava();+
      In C++ JNI DLL:

      +CDialogInJava dlg; // a Dialog Class from dialog resource template+
      +JNIEXPORT void JNICALL Java_test_DialogInJava_paint+
      +(JNIEnv* env, jobject canvas, jobject graphics)+
      +JAWT awt;+
      +JAWT_DrawingSurface ds;+
      +JAWT_DrawingSurfaceInfo dsi;+
      +jawt_Win32DrawingSurfaceInfo* dsi_win;+
      +jint lock;+
      +dsi_win = (jawt_Win32DrawingSurfaceInfo*)dsi->platformInfo;+
      +CWnd wnd;+
      +*{color:#0000ff}if (dlg.Create(dlg.IDD, &wnd) == TRUE)*+
      +*    dlg.MoveWindow(&rc);*+
      +*    dlg.ShowWindow(SW_SHOW);*+
      but after the paint func executed, and the control is returned from jni dll to the java application, the java application become no response to any input, the cursor keep busy.
      If I just use the HDC to draw lines, the system seems ok.
      The environment is jdk 1.6 and microsoft visual studio2008.

      Does anybody have the jni and mfc experience? How to modify the code?

      Edited by: Flyblue on Jan 24, 2010 5:28 AM