Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 103879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:11:37+00:00 2026-05-11T01:11:37+00:00

In Java 1.4 you could use ((SunToolkit) Toolkit.getDefaultToolkit()).getNativeWindowHandleFromComponent() but that was removed. It looks

  • 0

In Java 1.4 you could use ((SunToolkit) Toolkit.getDefaultToolkit()).getNativeWindowHandleFromComponent() but that was removed.

It looks like you have to use JNI to do this now. Do you have the JNI code and sample Java code to do this?

I need this to call the Win32 GetWindowLong and SetWindowLong API calls, which can be done via the Jawin library.

I would like something very precise so I can pass a reference to the JDialog or JFrame and get the window handle.

Swing transparency using JNI may be related.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:11:37+00:00Added an answer on May 11, 2026 at 1:11 am

    The following code lets you pass a Component to get the window handle (HWND) for it. To make sure that a Component has a corresponding window handle call isLightWeight() on the Component and verify that it equals false. If it doesn’t, try it’s parent by calling Component.getParent().

    Java code:

    package win32; public class Win32 {     public static native int getWindowHandle(Component c); } 

    Header file main.h:

    /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class win32_Win32 */  #ifndef _Included_win32_Win32 #define _Included_win32_Win32 #ifdef __cplusplus extern 'C' { #endif /*  * Class:     win32_Win32  * Method:    getWindowHandle  * Signature: (Ljava/awt/Component;Ljava/lang/String;)I  */ JNIEXPORT jint JNICALL Java_win32_Win32_getWindowHandle   (JNIEnv *, jclass, jobject); #ifdef __cplusplus } #endif #endif 

    The C source main.c:

    #include<windows.h> #include <jni.h> #include <jawt.h> #include <jawt_md.h>  HMODULE _hAWT = 0;  JNIEXPORT jint JNICALL Java_win32_Win32_getWindowHandle   (JNIEnv * env, jclass cls, jobject comp) {     HWND hWnd = 0;     typedef jboolean (JNICALL *PJAWT_GETAWT)(JNIEnv*, JAWT*);     JAWT awt;     JAWT_DrawingSurface* ds;     JAWT_DrawingSurfaceInfo* dsi;     JAWT_Win32DrawingSurfaceInfo* dsi_win;     jboolean result;     jint lock;      //Load AWT Library     if(!_hAWT)         //for Java 1.4         _hAWT = LoadLibrary('jawt.dll');     if(!_hAWT)         //for Java 1.3         _hAWT = LoadLibrary('awt.dll');     if(_hAWT)     {         PJAWT_GETAWT JAWT_GetAWT = (PJAWT_GETAWT)GetProcAddress(_hAWT, '_JAWT_GetAWT@8');         if(JAWT_GetAWT)         {             awt.version = JAWT_VERSION_1_4; // Init here with JAWT_VERSION_1_3 or JAWT_VERSION_1_4             //Get AWT API Interface             result = JAWT_GetAWT(env, &awt);             if(result != JNI_FALSE)             {                 ds = awt.GetDrawingSurface(env, comp);                 if(ds != NULL)                 {                     lock = ds->Lock(ds);                     if((lock & JAWT_LOCK_ERROR) == 0)                     {                         dsi = ds->GetDrawingSurfaceInfo(ds);                         if(dsi)                         {                             dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;                             if(dsi_win)                             {                                 hWnd = dsi_win->hwnd;                             }                             else {                                 hWnd = (HWND) -1;                             }                             ds->FreeDrawingSurfaceInfo(dsi);                         }                         else {                             hWnd = (HWND) -2;                         }                         ds->Unlock(ds);                     }                     else {                         hWnd = (HWND) -3;                     }                     awt.FreeDrawingSurface(ds);                 }                 else {                     hWnd = (HWND) -4;                 }             }             else {                 hWnd = (HWND) -5;             }         }         else {             hWnd = (HWND) -6;         }     }     else {         hWnd = (HWND) -7;     }     return (jint)hWnd;  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The equivalent statement in Ruby: date_wanted = :created_on title_date =… May 11, 2026 at 3:10 pm
  • added an answer I'd do this in a helper def fruit_size(fruit) list =… May 11, 2026 at 3:10 pm
  • added an answer Isn't ID a number? Then don't wrap it in quotes:… May 11, 2026 at 3:10 pm

Related Questions

In java <1.5, constants would be implemented like this public class MyClass { public
I need a way to bind POJO objects to an external entity, that could
At work today, I came across the volatile keyword in Java. Not being very
The Gang of Four's Design Patterns uses a word processor as an example for

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.