Solved

HWND of a Java window

Posted on 1998-12-12
9
1,292 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 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 covers a step-by-step guide to install VisualVM launcher in eclipse.

707 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