我想获取 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* 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
地址是0xcccccccc
(没用过)。
我做错什么了吗?
SDL 维基页面在备注部分说info.version
使用前必须初始化。代码示例建议使用SDL_VERSION(&info.version);
在查询WM信息之前。
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);
HWND hwnd = wmInfo.info.win.window;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)