I would like to get the handle of a SDL2 window, to use it with WinApi.
I retrieve that handle with the following code :
/* 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;
But at this point, hwnd
adress is 0xcccccccc
(unused).
Did I do something wrong?
SDL Wiki page in remarks section says that info.version
must be initialised before usage. Code example suggests using SDL_VERSION(&info.version);
before querying WM info.
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(window, &wmInfo);
HWND hwnd = wmInfo.info.win.window;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With