Solved

HWND of a Java window

Posted on 1998-12-12
9
1,275 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running Jira on Raspberry PI 2? 3 251
Securing Jmx Console and web console 2 64
jar file executable 12 39
configure dependency in POM for new database 3 15
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

912 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

17 Experts available now in Live!

Get 1:1 Help Now