Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to java .I add one extra menu on system menu now I want to handle an event on the system menu in java swings application i prepare a dll for that in c++ and i am unable to handle the event on system menu through dll using wndproc method through JNI if there any one who helps me to do this.
Posted
Updated 30-Jul-11 18:13pm
v2

You'll find the JNI code here:
SWT: The Standard Widget Toolkit[^]

I know SWT is not Swing - but SWT has the required JNI code.

Remember that Swing is built on top of the original objects and framework of AWT.

Inside the $(JDK)\include folder you'll find jawt.h
Inside the $(JDK)\include\win32 you'll find jawt_md.h

jawt_Win32DrawingSurfaceInfo allows you to access the native window handle.

Try subclassing the window using SetWindowLongPtr[^] with GWLP_WNDPROC

Here is an example:
Windows subclassing and hooking with C++ classes[^]

You'll need to update the example code as shown in the comments by Member 3644181

I've found that Jace[^] works nicely - It eases JNI development.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Abhinav S 31-Jul-11 6:01am    
Detailed answer. My 5.
Espen Harlinn 31-Jul-11 6:03am    
Thank you, Abhinav :)
Himanshu Bajpai 3-Aug-11 7:11am    
sir I have added one own menu item in window menu using jni,vc++,java. sir I want to handle event on that item using jni.how it can be possible. sir this can be done by jinvoke package in java.This package contain user32 class.so it can be done by jinvoke package. But sir I can't use this package because this is licence version package.And I don't have the licence of this package.so I choose the process of jni.And I have added one own menu in window menu using findwindow,Getsystemmenu and insertmenu. but I am not understanding that how can get handle of window menu and message from window menu when click on own window menu item in java.when click on own window menu item in java and handle of window menu pass to vc++ code.how it can be possible.please sir help me.
Richard MacCutchan 31-Jul-11 6:26am    
5 from me too, something I didn't know. I still can't see why anyone would want to do this, it sort of defeats the whole purpose of writing in Java.
Espen Harlinn 31-Jul-11 6:49am    
Thank you, Richard :)
OP states that he is new to java, maybe he has a large codebase in c++
I don't think you can do this, all events will be handled by the JVM so your wndproc procedure will not get called. Espen has given a great explanation of this.
 
Share this answer
 
v2
Comments
Himanshu Bajpai 3-Aug-11 7:05am    
sir I have added one own menu item in window menu using jni,vc++,java. sir I want to handle event on that item using jni.how it can be possible. sir this can be done by jinvoke package in java.This package contain user32 class.so it can be done by jinvoke package. But sir I can't use this package because this is licence version package.And I don't have the licence of this package.so I choose the process of jni.And I have added one own menu in window menu using findwindow,Getsystemmenu and insertmenu. but I am not understanding that how can get handle of window menu and message from window menu when click on own window menu item in java.when click on own window menu item in java and handle of window menu pass to vc++ code.how it can be possible.please sir help me.
Richard MacCutchan 3-Aug-11 7:14am    
I'm still rather confused as to why you are doing this. Why not create either a Windows program or a Java program, and forget trying to mix the two technologies. Using one or the other would make your task much simpler.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900