?
Solved

HWND of a Java window

Posted on 1998-12-12
9
Medium Priority
?
1,313 Views
Last Modified: 2008-02-01
How can get the HWND of a window created by Java (for example a Canvas object). I'm working with both sun VM (jdk 1.1.6)and Microsoft's JView (Windows OS).
0
Comment
Question by:adib
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229411
HWND is internal handle of window in WindowsOS. you are not supposed to use it from Java (and you can't if your Java program runs on Solaris).

why do you need this ? if you really need it - the answer is - you need to use native methods for Sun's VM (JView probably has some kind of internal support). but in both cases you lose the platform independence - your program will work only on Windows machines ...
0
 
LVL 8

Accepted Solution

by:
diakov earned 400 total points
ID: 1229412
You can do this only with Microsoft J++.

Control instance = this.getActiveControl();
if (instance != null)
{
  int hWnd = instance.getHandle();  
}

As 'heyhey_' emphasized, this only renders Java platform dependend. This is what MS made out of Java.

Enjoy,
  Nik.
 
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Expert Comment

by:gadio
ID: 1229413
adib, you can do this with jdk but its a bit tricky. What you can do is ask the OS to give you the HWND of a given point on the screen (if you know where your screen is). The problem with this approach is that the window can be partially or fully covered and then you get the wrong HWND. Use that only when you know where your window is and that its not covered. The best solution I found to the problem was to name the window (the title) with a known and unique name and then to browse and find the HWND  according to the name (the win32 API lets you do that. I don't remeber the function names, I'll have to look into the code).
0
 
LVL 8

Expert Comment

by:diakov
ID: 1229414
Remark to 'gadio',

This is native solution. But it works fine since I also used it.

Cheers,
  Nik
0
 
LVL 6

Expert Comment

by:gadio
ID: 1229415
[for diakov] - Nik, I didn't quite understand. Will your solution work on jdk without j++?
0
 
LVL 8

Expert Comment

by:diakov
ID: 1229416
[for gadio] no, but I wanted explicitly to point that it is a platform solution too so nobody gets confused. With WIN API you can enlist all windows and examine their titles, window class names and attributes, but these are features of the peer.

I admit, it is a more clear one since it is JDK compliant.

Cheers,
  Nik
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229417
[for gadio and diakov]

>> How can get the HWND of a window created by Java (for example a Canvas object).

don't even try to do it :-)))

cheers
  heyhey
0
 
LVL 1

Expert Comment

by:Hans_Klose
ID: 1229418
If you know that your program is for windows.  And you don't have to worry about porting it. Just use VJ++ and call API in Win32 object. If not ,but you still want it. use JNI to get a 32bit a int for thats what a HWND is. The api its enumWindow or such

It isn't a law to be OS independent..yet anyway, so what ever make sence in your program.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question