• Post Reply Bookmark Topic Watch Topic
  • New Topic

A tough one...marrying Java and MFC...GUI related.  RSS feed

 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Boy this is a tough one I'm afraid....

What I want to do is have a Java application act like a modeless dialog on top of an MFC application.

In other words, the dialog stays up and visible, but just loses focus and allows the application underneath, which takes up the entire screen, to be interacted with.

The way it is now, the Java app draws over the MFC application, and disapears when the user clicks on the MFC application. So it is modeless, but not acting like a dialog embeddd in the MFC application that would stay alive on top of the MFC frame.

The boss doesn't want the user to have to alt-tab over to see the Java application (that is talking to the MFC application via COM).

Can this be done?


BTW, this is the company's first use of Java (at my suggestion...not my first use by a long shot), so please help me out here or it's back to MFC!
[ August 03, 2004: Message edited by: Darrin Smith ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, for sure you're going to have to get them into the same OS process, meaning that the MFC program is going to have to use JNI and createJavaVM() to start Java. I've never done something like this with a GUI host app, so I really don't know how they'll play together, but I think the first step might just be to try that, and see what happens. If the two apps remain fairly loosely coupled, then this might work out OK.
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering about having the Java app run as a Windows service (know this can be done) and have the MFC app start the service.

Does this sound plausible and maybe easier?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know much about Windows, really, but can Services even have GUIs? If they can, wouldn't the Task Manager put them into their own "layer" on the desktop?

I'm just talking into my hat, here, though.
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
I don't know much about Windows, really, but can Services even have GUIs? If they can, wouldn't the Task Manager put them into their own "layer" on the desktop?


I asked myself those same questions shortly after posting the initial response. I have read that it is possible for the service to have a GUI, but normally not done that way (usually a GUI helper app communicates with the service). I think you are right about the service going into its own "layer" though...so that is out.

So...if nobody else has any suggestions, I suppose it is off to see just how to use createJavaVM and pray that it works!
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That might well be the only solution.
Any others would involve constantly changing the priority of the window which would cause flickering at least (and loosing focus on the background window).

Of course a better solution still would be to forget about Java for this application and write is as a DLL which you can call from the MFC application as a plugin.
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeroen Wenting:
Of course a better solution still would be to forget about Java for this application and write is as a DLL which you can call from the MFC application as a plugin.


The Java application does a lot...database access, GUI, COM, XML, etc. All of this could be done as a DLL I suppose, but to me, save for this one issue, it is a whole lot easier to use Java to do these things. Besides, we want to use this as a sort of pilot project for Java.

If worse comes to worse though, I guess that I can try to convert the application to a DLL and scrap Java.
 
Dom King
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darrin,

Are you still pursuing an answer on this? Hope so...

Your best approach might be to host your Java class inside the MFC app. This way MFC could enforce modality when you call DoModal() on your dialog. Here are three ways to do this:

(1) You could use the Invocation API. The Invocation API on Win32 also supports interoperability between native windows/GDI and Java AWT. I'm not sure if this approach will meet all of your goals without knowing more about your app.

(2) You could possibly host the Java controls inside the MFC dialog using Java/ActiveX bridging technology from Sun or another vendor.

(3) Change you MFC Dialog to an HtmlDialog, make an Applet-derived class for your Java application, and host your Java applet in the HTML layout for the dialog using Sun's technology for hosting Java inside Internet Explorer. You may need to grant the applet greater security permissions if need be too.

If these approaches don't work, instead of rewriting everything in C++, you may want to take a look at NewJ Library. It'll let you use the Java API naturally inside your C++/MFC app.

NewJ info: http://www.pure-native.com/newj.html
 
Ryan Vandenheuvel
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any update on this?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!