JWindow Handle  
Author Message
mromarkhan





PostPosted: 2004-5-24 8:31:00 Top

java-programmer, JWindow Handle
Peace be unto you.
Make sure to pass jawt.lib (C:\j2sdk1.4.2_04\lib\jawt.lib) to your compiler.

The code for MyCanvas.java is in C:\j2sdk1.4.2_04\include\jawt.h
Look in C:\j2sdk1.4.2_04\include\win32\jawt_md.h to see more instructions on how to obtain a window handle.
For instance, struct jawt_Win32DrawingSurfaceInfo can be manipulated like the following.
HWND hwnd = dsi_win->hwnd;
HDC hdc = dsi_win->hdc;


<code>
javac MyCanvas.java
REM generate MyCanvas.h
javah -jni MyCanvas
REM compile c file
REM include headers from java, compile to object not executable
gcc -g -O2 -c -IC:/MinGW/include -Ic:/j2sdk1.4.2_04/include -Ic:/j2sdk1.4.2_04/include/win32 -g MyCanvas.c
REM jawt.lib is treated like an object;otherwise it will complain about not finding get awt
dllwrap -IC:/MinGW/include --output-def MyCanvas.def --add-stdcall-alias -o MyCanvas.dll MyCanvas.o C:\j2sdk1.4.2_04\lib\jawt.lib -lgdi32
REM need jawt.dll in path not class path; -Djava.library.path gave me problems;otherwise get unsatisfied link error
set path=C:\j2sdk1.4.2_04\jre\bin;C:\WINDOWS\SYSTEM;.;C:\WINDOWS
java MyCanvas
</code>

By the way there is the FindWindow function. (Microsoft Q124103: HOWTO: Obtain a Console Window Handle (HWND))

Have a Good Day.


-- References
Mumit Khan
http://www.xraylith.wisc.edu/~khan/software/gnu-win32/
Davanum Srinivas
http://www.javaworld.com/javaworld/javatips/jw-javatip86.html