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