Wiki Page Content

Differences between revisions 12 and 13
Revision 12 as of 2012-09-05 05:34:53
Size: 2503
Editor: ChrisBush
Comment: Code example (corrected, expanded)
Revision 13 as of 2013-02-11 17:35:14
Size: 2539
Comment: Changed code sample to use C instead of C++.
Deletions are marked like this. Additions are marked like this.
Line 24: Line 24:
#include <SDL2/SDL.h>
#include <SDL2/SDL_syswm.h>
#include <iostream>
#include "SDL.h"
#include "SDL_syswm.h"
Line 28: Line 27:
using std::cout;
Line 30: Line 28:
int main(int argc, char* argv[]){
int main(int argc, char *argv[]) {
Line 39: Line 36:
  if(SDL_GetWindowWMInfo(window,&info)){ // the call returns true on success   if(SDL_GetWindowWMInfo(window,&info)) { // the call returns true on success
Line 41: Line 38:
    cout << "This program is running SDL version "
      << (int)info.version.major << "."
      << (int)info.version.minor << "."
      << (int)info.version.patch << " on
";
    switch(info.subsystem){
      case SDL_SYSWM_UNKNOWN: cout << "an unknown system!"; break;
      case SDL_SYSWM_WINDOWS: cout << "Microsoft Windows(TM)"; break;
      case SDL_SYSWM_X11: cout << "X Window System"; break;
      case SDL_SYSWM_DIRECTFB: cout << "DirectFB"; break;
      case SDL_SYSWM_COCOA: cout << "Apple OS X"; break;
      case SDL_SYSWM_UIKIT: cout << "UIKit"; break;
    const char *subsystem = "an unknown system!";
    switch(info.subsystem) {
      case SDL_SYSWM_UNKNOWN: break;
      case SDL_SYSWM_WINDOWS: subsystem = "Microsoft Windows(TM)"; break;
      case SDL_SYSWM_X11: subsystem = "X Window System"; break;
      case SDL_SYSWM_DIRECTFB: subsystem = "DirectFB"; break;
      case SDL_SYSWM_COCOA: subsystem = "Apple OS X"; break;
      case SDL_SYSWM_UIKIT: subsystem = "UIKit"; break;
Line 53: Line 47:

    SDL_Log("This program is running SDL version %d.%d.%d on %s\n",
        (int)info.version.major,
        (int)info.version.minor,
        (int)info.version.patch,
        subsystem);
Line 56: Line 56:
    cout << "Couldn't get window information: " << SDL_GetError();     SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Couldn't get window information: %s\n", SDL_GetError());

SDL_GetWindowWMInfo

Use this function to get driver specific information about a window.

Syntax

SDL_bool SDL_GetWindowWMInfo(SDL_Window*    window,
                             SDL_SysWMinfo* info)

Function Parameters

window

the window about which information is being requested

info

an SDL_SysWMinfo structure filled in with window information; see Remarks for details

Return Value

Returns SDL_TRUE if the function is implemented and the version member of the info struct is valid, or SDL_FALSE if the information could not be retrieved; call SDL_GetError() for more information.

Code Examples

#include "SDL.h"
#include "SDL_syswm.h"


int main(int argc, char *argv[]) {
  SDL_Init(0);
  SDL_Window* window = SDL_CreateWindow("",0,0,0,0,SDL_WINDOW_HIDDEN);
  
  SDL_SysWMinfo info;
  
  SDL_VERSION(&info.version); // initialize info structure with SDL version info
  
  if(SDL_GetWindowWMInfo(window,&info)) { // the call returns true on success
    // success
    const char *subsystem = "an unknown system!";
    switch(info.subsystem) {
      case SDL_SYSWM_UNKNOWN:   break;
      case SDL_SYSWM_WINDOWS:   subsystem = "Microsoft Windows(TM)";  break;
      case SDL_SYSWM_X11:       subsystem = "X Window System";        break;
      case SDL_SYSWM_DIRECTFB:  subsystem = "DirectFB";               break;
      case SDL_SYSWM_COCOA:     subsystem = "Apple OS X";             break;
      case SDL_SYSWM_UIKIT:     subsystem = "UIKit";                  break;
    }

    SDL_Log("This program is running SDL version %d.%d.%d on %s\n", 
        (int)info.version.major,
        (int)info.version.minor,
        (int)info.version.patch,
        subsystem);
    
  } else {
    // call failed
    SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Couldn't get window information: %s\n", SDL_GetError());
  }
  
  SDL_DestroyWindow(window);
  SDL_Quit();
  
}

Remarks

You must include SDL_syswm.h for the declaration of SDL_SysWMinfo.

The info structure must be initialized with the SDL version, and is then filled in with information about the given window, as shown in the Code Example.


CategoryAPI, CategoryVideo, CategorySWM

None: SDL_GetWindowWMInfo (last edited 2016-10-13 20:36:31 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit