C 获取SDL2应用程序的窗口句柄
我想获得SDL2窗口的句柄,以便与WinApi一起使用 我使用以下代码检索该句柄:C 获取SDL2应用程序的窗口句柄,c,winapi,sdl,sdl-2,C,Winapi,Sdl,Sdl 2,我想获得SDL2窗口的句柄,以便与WinApi一起使用 我使用以下代码检索该句柄: /* All the SDL initalisation... */ SDL_Window* window = SDL_CreateWindow("My Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, RESX, RESY, SDL_WINDOW_SHOWN); SDL_Renderer* ren
/* 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
地址是0xcccc
(未使用)
我做错什么了吗?在备注部分说,info.version
必须在使用前进行初始化。代码示例建议使用SDL\u版本(&info.VERSION)代码>在查询WM信息之前
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);
HWND hwnd = wmInfo.info.win.window;
添加SDL\u版本(&wmInfo.VERSION)调用SDL\u GetWindowWMInfo
之前,请执行code>。