SDL 2.0 : How to get the HWND from SDL_SysWMinfo

c, c-preprocessor, sdl, winapi

Solution

Purely based on the declarations of the `struct`, I would imaginge you reference the `HWND` like this:

application->h_window = application->system_info.info.win.window;

Problem

The Problem : I'm trying to make a transparent window by using win32 and SDL 2.0, since the official API for it hasn't been released. I've been having trouble referencing the window field to get to the HWND. It gives me this error currently ``` F:\C programs and compiliers\C\SDL_test\main.c||In function 'get_system_data':| F:\C programs and compiliers\C\SDL_test\main.c|220|error: 'union <anonymous>' has no member named 'window'| ||=== Build finished: 1 errors, 0 warnings (0 minutes, 0 seconds) ===| ``` I understand that it declares the structure with a linker dependent union like this : ``` struct SDL_SysWMinfo { SDL_version version; SDL_SYSWM_TYPE subsystem; union { #if defined(SDL_VIDEO_DRIVER_WINDOWS) struct { HWND window; /**< The window handle */ } win; #endif #if defined(SDL_VIDEO_DRIVER_X11) struct { Display *display; /**< The X11 display */ Window window; /**< The X11 window */ } x11; #endif #if defined(SDL_VIDEO_DRIVER_DIRECTFB) struct { IDirectFB *dfb; /**< The directfb main interface */ IDirectFBWindow *window; /**< The directfb window handle */ IDirectFBSurface *surface; /**< The directfb client surface */ } dfb; #endif #if defined(SDL_VIDEO_DRIVER_COCOA) struct { NSWindow *window; /* The Cocoa window */ } cocoa; #endif #if defined(SDL_VIDEO_DRIVER_UIKIT) struct { UIWindow *window; /* The UIKit window */ } uikit; #endif /* Can't have an empty union */ int dummy; } info; }; #endif /* SDL_PROTOTYPES_ONLY */ ``` I just don't know how to access the field properly in an "anonymous" union. Research I've done : wiki : http://wiki.libsdl.org/SDL_VERSION http://wiki.libsdl.org/SDL_SysWMinfo http://wiki.libsdl.org/SDL_GetWindowWMInfo SO : How to center a SDL window in Linux? There were some other stackoverflow that had very similar code to that, they are irrelevant since they didn't work either. The Code : ``` #include "test.h" #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #define WIN_32_LEAN_AND_MEAN /* Trims all the fat from windows */ #include <windows.h> #define SDL_MAIN_HANDLED #ifndef __WIN32__ #define __WIN32__ #endif // __WIN32__ #include "SDL2/SDL.h" #include "SDL2/SDL_mixer.h" #include "SDL2/SDL_syswm.h" void get_system_data( application_data* application ) { SDL_VERSION( &application->system_info.version ); if ( !SDL_GetWindowWMInfo( application->window, &application->system_info ) ) SDL_errorexit( "SDL_GetWindowWMInfo", SDL_LOG_CATEGORY_ERROR ); switch ( application->system_info.subsystem ) { case SDL_SYSWM_WINDOWS : break; default : printf( "Unhandled OS!\n" ); free_application_data( application ); exit( 1 ); break; } application->h_window = application->system_info.info.window; return; } ``` I only posted the relevant code here, I can post more if needed.

Original source