Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / May 2005

Tip: Looking for answers? Try searching our database.

Interfacing with applet

Thread view: 
Deodiaus - 19 May 2005 20:09 GMT
I am running WinXP and have a win32 application which is monitoring IE
(running a java applet).
I want to extract info rendered by a java applet.  I can find the
window's handle, but don't know quite how to get at the info in the
sunawtcanvas.  Are there any examples which illustrate this?
When an applet updates its java.applet.canvas, does the JVM call native
Windows API to display text on a screen, or does it position the fonts
on the canvas (what I think).
When the applet needs memory, does jvm do some sort of malloc via a
direct call to a C run-time lib?  In general, does the JVM directly
call the Win32 API or does it have its own interface?
I was reading the JNI documentation, but can't make sense of enough of
this.  Any sites which discuss this topic.
Deodiaus - 19 May 2005 20:25 GMT
I understand that the java API does most of what the Win32 api does.
But how does the JVM actually render an image.  It must talk to the
hardware at some point, in order to display the image.  It must have
some rudimentary understanding of a windows handle and the graphics
drivers, as well as limits on it size and bitdepths.
Boudewijn Dijkstra - 20 May 2005 14:03 GMT
>I am running WinXP and have a win32 application which is monitoring IE
> (running a java applet).
[quoted text clipped - 9 lines]
> I was reading the JNI documentation, but can't make sense of enough of
> this.  Any sites which discuss this topic.

Of course you can always look in the SCSL sources how everything is done.
Deodiaus - 26 May 2005 17:50 GMT
I have my Win32 application and IE running a java applet.  My
application gets the hWnd of IE and its children hWnd's .  Using spy++
you can see this hierarchy as

IEFrame
->WorkerW
--->WorkerW
----->msctls status bar32
----->Shell DocObjectViewer
------->Internet Explorer_Server
--------->JavaPluginControlwindow
----------->java.plugin.viewer.IExplorerEmbeddedFrame
------------->sunawtcanvas
--------------->sunawtcanvas

Does anyone know why MS's IE has two sunawtcanvas's.  My guess is that
the first one of these is the sunawtcomponent.  Is that true?
Given the sunawtcanvas HWND, can I

----------subclass.cpp------------
int subclass( HWND& hWndSunAwtCanvas2)
{
//    jobject graphics;
 int iRc=0;
#ifdef  _USEJVM
 try {
    JavaVM *jvm;
    jsize mySize;

    jint status =
       JNI_GetCreatedJavaVMs( &jvm, mySize, &mySize);

    if (JNI_ERR==status) {
        OutputDebugString("failed in JNI_CreateJavaVM\n");
        iRc=-5;
    } else {
        JNIEnv* env ;
        jint status2 =
        JNI_GetDefaultJavaVMInitArgs((void**)&env);

        if (JNI_ERR==status2) {
            OutputDebugString("failed in JNI_GetDefaultJavaVMInitArgs\n");
            iRc=-9;
        } else {

            JAWT awt;
            jobject canvas=(jobject) hWndSunAwtCanvas2;
            // Get the AWT
            awt.version = JAWT_VERSION_1_4;
           jboolean result;
            result = JAWT_GetAWT(env, &awt);// need to get the awt from IE, not
your local version
            if (result == JNI_FALSE){
                OutputDebugString("AWT Not Found\n");
                iRc=-8;
            } else {

                JAWT_DrawingSurface* ds;
                JavaVMOption options[1];
                JavaVMInitArgs vm_args;
                //JNIEnv_ myJNIEnv;// need to init this??
                memset( &vm_args, 0, sizeof(vm_args));
                vm_args.version = JNI_VERSION_1_4;
                vm_args.nOptions = 1;
                vm_args.options = options;

                // Get the drawing surface
                ds = awt.GetDrawingSurface(env, canvas);
                if (ds == NULL){
                    OutputDebugString("NULL drawing surface\n");
                    iRc=-3;
                } else {
                    jint lock;
                    // Lock the drawing surface
                    lock = ds->Lock(ds);
                    if ((lock & JAWT_LOCK_ERROR) != 0){
                        OutputDebugString("Error locking surface\n");
                        iRc=-2;
                    } else {
                 //try
                        JAWT_DrawingSurfaceInfo* dsi;
                        // Get the drawing surface info
                        dsi = ds->GetDrawingSurfaceInfo(ds);
                        if (dsi == NULL){
                            OutputDebugString("Error getting surface info\n");
                            iRc=-6;
                        } else {
                            JAWT_Win32DrawingSurfaceInfo* dsi_win;

                            // Get the platform-specific drawing info
                            dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
                            if (dsi_win == NULL){
                                OutputDebugString("Error getting platform-specific drawing
info\n");
                                iRc=-7;
                            } else {

                                //////////////////////////////
                                // !!! DO PAINTING HERE !!! //
                                //////////////////////////////
                                //dsi_win.
                                //jint ret = reinterpret_cast<jint>(dsiwin->hwnd);
                                if (hWndSunAwtCanvas2==dsi_win->hwnd) {
                                    playDIB3(dsi_win->hwnd);
                                } else{
                                    OutputDebugString("Error dsi_win->hwnd\n");

                                }//
                                // Free the drawing surface info
                                ds->FreeDrawingSurfaceInfo(dsi);
                            }//

                                                         //
                        // Unlock the drawing surface
                        ds->Unlock(ds);
                        }
                    }//
                    // Free the drawing surface
                    awt.FreeDrawingSurface(ds);
                }//
                jvm->DetachCurrentThread();
            }
        }//JAWT_GetAWT
    }//JNI_CreateJavaVM
 } catch(...){
    OutputDebugString("Exception caught\n");
    throw;
 }

 return iRc;
}
------------eof----------------------

Now, I want to subclass the java applet through the use of JNI like
this example from sun's jni.
----------------------WindowUtil.java
import java.awt.*;
import javax.swing.*;

public class WindowUtil extends Canvas {
   static { System.load("c:\\mylib.dll"); }
   public native void flashInTaskBar(Component c, boolean flash);

   public void flash(final JFrame frame, final int intratime, final
int intertime, final int count) {
       new Thread(new Runnable() {
           public void run() {
               try {
                   // flash on and off each time
                   for(int i=0; i<count; i++) {
                       flashInTaskBar(frame,true);
                       Thread.sleep(intratime);
                       flashInTaskBar(frame,true);
                       Thread.sleep(intertime);
                   }
                   // turn the flash off
                   flashInTaskBar(frame,false);
               } catch (Exception ex) {
                   System.out.println(ex.getMessage());
               }
       }}).start();
   }
}
------------eof----------------------
----------myutil.c ---------------------
JNIEXPORT void JNICALL Java_flash_WindowUtil_flashInTaskBar
 (JNIEnv *env, jobject canvas, jobject component, jboolean flash)
{
    JAWT awt;
    JAWT_DrawingSurface* ds;
    JAWT_DrawingSurfaceInfo* dsi;
    JAWT_Win32DrawingSurfaceInfo* dsi_win;
    jboolean result;

    jint lock;

    // Get the AWT
    awt.version = JAWT_VERSION_1_3;
    result = JAWT_GetAWT(env, &awt);
    assert(result != JNI_FALSE);

    // Get the drawing surface
    ds = awt.GetDrawingSurface(env, component);
    if(ds == NULL)
        return;

    // Lock the drawing surface
    lock = ds->Lock(ds);
    assert((lock & JAWT_LOCK_ERROR) == 0);

    // Get the drawing surface info
    dsi = ds->GetDrawingSurfaceInfo(ds);

    // Get the platform-specific drawing info
    dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;

    FlashWindow(dsi_win->hwnd, flash);

    // Free the drawing surface info
    ds->FreeDrawingSurfaceInfo(dsi);
    // Unlock the drawing surface
    ds->Unlock(ds);
    // Free the drawing surface
    awt.FreeDrawingSurface(ds);
}
------------eof----------------------

Will this approach let me get into the java model and extract the info
being typed on the screen.  Any comments or suggestions on how to read
info from a java applet, which is one over which I have no control?

also see
http://msdn.microsoft.com/library/periodic/period00/hood0200.htm

http://java.sys-con.com/read/48177.htm

http://www.codeproject.com

          apihijack

          subhook
Walter Deodiaus - 26 May 2005 21:24 GMT
1) Does anyone know how to get to the Sun supplied ActiveX control which
contains the jvm?
2) Another approach is to intercept the communications between the java
applet and IE.  Does anyone know how to do this?

> I have my Win32 application and IE running a java applet.  My
> application gets the hWnd of IE and its children hWnd's .  Using spy++
[quoted text clipped - 217 lines]
>
>            subhook


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.