2
得到HWND的問題:SDL 2.0:如何從SDL_SysWMinfo
我試圖用win32和SDL 2.0做一個透明的窗口,因爲它的官方API還沒有被釋放。我一直無法引用窗口字段到達HWND。它給了我這個錯誤當前
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) ===|
據我所知,它聲明的結構與連接相關的工會這樣的:
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 */
我只是不知道如何正確地訪問領域的一個「匿名「聯盟。
研究我做:
維基:
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?
還有一些其他的stackoverflow有非常類似的代碼,它們是無關的,因爲他們也沒有工作。
驗證碼:
#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;
}
我只貼出相關的代碼在這裏,如果需要,我可以發佈更多。