2014-06-09 64 views
0

我想獲得SDL2窗口的句柄,以便在WinApi中使用它。獲取SDL 2應用程序的窗口句柄

我檢索與下面的代碼,手柄:

/* All the SDL initalisation... */ 
SDL_Window* window = SDL_CreateWindow("My Window", SDL_WINDOWPOS_UNDEFINED, 
         SDL_WINDOWPOS_UNDEFINED, RESX, RESY, SDL_WINDOW_SHOWN); 
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); 
if (window == NULL || renderer == NULL) { 
    MessageBox(NULL, L"SDL initialisation error", NULL, MB_OK); 
    exit(-1); 
} 

SDL_SysWMinfo wmInfo; 
SDL_GetWindowWMInfo(window, &wmInfo); 
HWND hwnd = wmInfo.info.win.window; 

但在這一點上,hwnd ADRESS是0xcccccccc(未使用)。

我做錯了什麼?

+1

在調用SDL_GetWindowWMInfo之前添加'SDL_VERSION(&wmInfo.version);'。 – keltar

+0

謝謝,它工作:) – Lovy

回答

1

SDL Wiki page在備註部分說info.version必須在使用前初始化。代碼示例建議在查詢WM信息之前使用SDL_VERSION(&info.version);