[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

HWND of a Java window

Posted on 1998-12-12
9
Medium Priority
?
1,299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

649 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