SDL Tip – Window Handle

March 22nd, 2010 by Tim Jones Leave a reply »

You can easily grab the handle of the Window using a single function inside SDL. Please note, I don’t recommend you do this unless you really need to do something OS specific. This will almost certainly break cross-platform compatibility.

SDL_SysWMinfo SysInfo; //Will hold our Window information
SDL_VERSION(&SysInfo.version); //Set SDL version
 
if(SDL_GetWMInfo(&SysInfo) <= 0) {
    printf("%s : %d\n", SDL_GetError(), SysInfo.window);
    return false;
}
 
HWND WindowHandle = SysInfo.window; //There it is, Win32 handle

You can check out the other possible values to grab here:
http://sdl.beuc.net/sdl.wiki/SDL_SysWMInfo

If this is something you want to do, but you still want your game/application to be cross platform, then you can use pre-processor directives:

#ifdef __WIN32__
HWND WindowHandle = SysInfo.window; //Win32 window handle
#else
Window WindowHandle = SysInfo.window; //X11 window handle
#endif

Note: This might be useful if you are making an application that you want to sit in the tray, or you want the window to dock (just a few examples).

Share and Enjoy:
  • Digg
  • del.icio.us
  • DZone
  • MisterWong
  • Reddit
  • StumbleUpon
  • Technorati
  • Slashdot
  • LinkedIn
  • MySpace
  • Yahoo! Buzz

Did you like this tutorial/blog post? Feel free to donate to keep more comin', and have more contests.

Advertisement

Leave a Reply