[CLOSED] Get hWnd of window

Started by Simon Felix, May 04, 2011, 17:51:26

Previous topic - Next topic

Simon Felix

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/

Matzon

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?
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();
	  }
	  
  }

Simon Felix

Quote from: Matzon on May 04, 2011, 18:30:10
a small hackup - ppossibly usefull?

Yeah :) Thank you very much!

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

jediTofu

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