Solved

HWND of a Java window

Posted on 1998-12-12
9
1,274 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 5

Expert Comment

by:scrapdog
ID: 1229410
0
 
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 200 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now