Hello Guest

[CLOSED] Get hWnd of window

  • 3 Replies
  • 10373 Views
[CLOSED] Get hWnd of window
« on: May 04, 2011, 17:51:26 »
Hi there

we use BASS as sound library for our game. The library needs the window handle of the application's window on initialization. Currently we can not provide this so the library uses a heuristic which sometimes fails.

It'd be useful if LWJGL exposed the window handle somehow.

I'm aware that the situation is complicated because there's no simple X window equivalent for example. But I wouldn't expect a platform independent mechanism to get hold of platform dependent data. Display.getHWnd() could throw exceptions on other platform or just return 0.

Cheers,
Simon
Download Cultris II, the fastest Tetris clone from http://gewaltig.net/

*

Offline Matzon

  • *****
  • 2242
Re: [RFE] Get hWnd of window
« Reply #1 on: May 04, 2011, 18:30:10 »
Not sure .. could expose them as an opaque handle to a bytebuffer, and then the addresss of that bytebuffer would be the handle. However you really really could screw around if you do that ...

a small hackup - ppossibly usefull?
Code: [Select]
private void printInternal() {
 
  try {
  long hdc = -1;
  long hwnd = -1;
  Object displayImpl = null;
 
  Method[] displayMethods = Display.class.getDeclaredMethods();
  for(Method m : displayMethods) {
  if(m.getName().equals("getImplementation")) {
  m.setAccessible(true);
  displayImpl = m.invoke(null, null);
  break;
  }
  }
 
  Field[] windowsDisplayFields = displayImpl.getClass().getDeclaredFields();
  for(Field f : windowsDisplayFields) {
  if(f.getName().equals("hwnd")) {
  f.setAccessible(true);
  hwnd = (Long) f.get(displayImpl);
  continue;
  }
 
  if(f.getName().equals("hdc")) {
  f.setAccessible(true);
  hdc = (Long) f.get(displayImpl);
  continue;
  }
  }
 
  System.out.println("Address of hWnd: " + hwnd);
  System.out.println("Address of hDc: " + hdc);
  } catch (Exception e) {
e.printStackTrace();
  }
 
  }

Re: [RFE] Get hWnd of window
« Reply #2 on: May 04, 2011, 21:04:20 »
a small hackup - ppossibly usefull?

Yeah :) Thank you very much!

Cheers,
Simon
Download Cultris II, the fastest Tetris clone from http://gewaltig.net/

Re: [RFE] Get hWnd of window
« Reply #3 on: May 06, 2011, 05:05:31 »
Just make a simple JNI class.  Use either FindWindow(null,"title of window") or there is a way to get a hWnd based on the current running process, but I don't remember that one right now....just search msdn.  This is if you don't want to mess with any LWJGL code.
cool story, bro