How to retrieve the HWND of a window?

There’s an SDL API command to create a SDL_Window from an arbitrary HWND, but is there any way to take a SDL_Window and retrieve its HWND?

Here’s why I need it:? I’m running into a bit of a problem with my input handling code.? I’ve got a routine that gets called in between rendering frames.? It calls SDL_PumpEvents and SDL_PeepEvents to process keyboard events, and it works well.? But Delphi has its own event pump, which means that any keyboard input is essentially a race condition: it could end up in the SDL event handler, where I want it… or it could be lost.

I can’t turn Delphi’s event pump off, and I wouldn’t want to.? It takes care of a lot of other very useful stuff.? But one thing I can do is hook an event handler (ie. callback routine) into it to get a first look at incoming events.? If I capture all relevant events in a queue, and then replay that queue into Window’s event queue right before calling SDL_PumpEvents, that will fix the race condition.

But to do that, I need to be able to define “relevant events.”? And for that I need the HWND of my SDL_Window to use as a filter. Is there any way to get at it?

Mason

Here’s the code I use for SDL2.

#include <SDL_syswm.h>

 //get the native whnd
 struct SDL_SysWMinfo wmInfo;
 SDL_VERSION(&wmInfo.version);

 if(-1 == SDL_GetWindowWMInfo(mSDLWindow, &wmInfo))
     throw std::runtime_error("Couldn't get WM Info!");

 Ogre::String winHandle;

 switch(wmInfo.subsystem)
 {

#ifdef WIN32
case SDL_SYSWM_WINDOWS:
// Windows code
winHandle = Ogre::StringConverter::toString((unsigned
long)wmInfo.info.win.window);
break;
#elif MACOSX
case SDL_SYSWM_COCOA:
//required to make OGRE play nice with our window
params.insert(std::make_pair(“macAPI”, “cocoa”));
params.insert(std::make_pair(“macAPICocoaUseNSView”, “true”));

     winHandle  = 

Ogre::StringConverter::toString(WindowContentViewHandle(wmInfo));
break;
#else
case SDL_SYSWM_X11:
winHandle = Ogre::StringConverter::toString((unsigned
long)wmInfo.info.x11.display);
winHandle += “:0:”;
winHandle += Ogre::StringConverter::toString((unsigned
long)wmInfo.info.x11.window);
break;
#endif
default:
throw std::runtime_error(“Unexpected WM!”);
break;
}On 18.06.2013 19:22, Mason Wheeler wrote:

There’s an SDL API command to create a SDL_Window from an arbitrary
HWND, but is there any way to take a SDL_Window and retrieve its HWND?

Here’s why I need it: I’m running into a bit of a problem with my
input handling code. I’ve got a routine that gets called in between
rendering frames. It calls SDL_PumpEvents and SDL_PeepEvents to
process keyboard events, and it works well. But Delphi has its own
event pump, which means that any keyboard input is essentially a race
condition: it could end up in the SDL event handler, where I want
it… or it could be lost.

I can’t turn Delphi’s event pump off, and I wouldn’t want to. It takes
care of a lot of other very useful stuff. But one thing I can do is
hook an event handler (ie. callback routine) into it to get a first
look at incoming events. If I capture all relevant events in a queue,
and then replay that queue into Window’s event queue right before
calling SDL_PumpEvents, that will fix the race condition.

But to do that, I need to be able to define “relevant events.” And for
that I need the HWND of my SDL_Window to use as a filter. Is there any
way to get at it?

Mason

Check out:

http://www.libsdl.org/cgi/docwiki.fcg/SDL_GetWMInfo
http://www.libsdl.org/cgi/docwiki.fcg/SDL_SysWMInfoOn Tue, Jun 18, 2013 at 2:22 PM, Mason Wheeler wrote:

There’s an SDL API command to create a SDL_Window from an arbitrary HWND,
but is there any way to take a SDL_Window and retrieve its HWND?

Here’s why I need it: I’m running into a bit of a problem with my input
handling code. I’ve got a routine that gets called in between rendering
frames. It calls SDL_PumpEvents and SDL_PeepEvents to process keyboard
events, and it works well. But Delphi has its own event pump, which means
that any keyboard input is essentially a race condition: it could end up in
the SDL event handler, where I want it… or it could be lost.

I can’t turn Delphi’s event pump off, and I wouldn’t want to. It takes care
of a lot of other very useful stuff. But one thing I can do is hook an
event handler (ie. callback routine) into it to get a first look at incoming
events. If I capture all relevant events in a queue, and then replay that
queue into Window’s event queue right before calling SDL_PumpEvents, that
will fix the race condition.

But to do that, I need to be able to define “relevant events.” And for that
I need the HWND of my SDL_Window to use as a filter. Is there any way to get
at it?

Mason


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Alejandro Santos