思路:
1。跳过由sdl直接创建弹出窗口,那么它的窗口应该是QT指定的窗口。
2。给SDL传递窗口Handle,由SDL_getenv("SDL_WINDOWID")来实现
3。在SDL调用系统函数CreateWindow前把它Filter下来,否则会生成一个独立的窗口。
4。更改当前窗口的消息循环.
印象中当时是参考1.26版本源代码来实现的,由于1.26与1.3相差比较大,因此走了一些弯路。
当时花了很多时间在处理消息循环上, 最终才形成下面的代码。
下面是SDL中需要更改的地方:
sdl1.3/src/video/win32/SDL_win32window.h:
extern void WIN_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool WIN_GetWindowWMInfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo *info);
+ HWND SDL_WindowId;
#endif /* _SDL_win32window_h */
sdl1.3/src/video/win32/SDL_win32window.c:
//在int WIN_CreateWindow(_THIS, SDL_Window * window)函数中
if ((window->flags & SDL_WINDOW_FULLSCREEN)
|| window->y == SDL_WINDOWPOS_CENTERED) {
y = bounds.y + (bounds.h - h) / 2;
} else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
if (bounds.x == 0) {
y = CW_USEDEFAULT;
} else {
y = bounds.y;
}
} else {
y = bounds.y + window->y + rect.top;
}
+// for inter window
+
+ {
+ BOOL SDL_windowid;
+ char *windowid;
+ LONG rtv;
+ windowid = SDL_getenv("SDL_WINDOWID");
+ SDL_windowid = (windowid != NULL);
+ if ( SDL_windowid ) {
+ SDL_WindowId = (HWND)SDL_strtoull(windowid, NULL, 0);
+ if ( SDL_WindowId == NULL ) {
+ SDL_SetError("Couldn't get user specified window");
+ return(-1);
+ }
+
+ /* DJM: we want all event's for the user specified
+ window to be handled by SDL.
+ */
+ //userWindowProc = (WNDPROCTYPE)GetWindowLongPtr(SDL_Window, GWLP_WNDPROC);
+ //rtv = SetWindowLongPtr(SDL_WindowId, GWLP_WNDPROC, (LONG_PTR)DefWindowProc);
+ //SDL_SetError("return = %d", rtv);
+ }
+ }
+
+ if (SDL_WindowId)
+ {
+ hwnd = SDL_WindowId;
+ SetWindowPos(hwnd, NULL, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));
+ }
+ else
+ {
+ hwnd =
+ CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL,
+ SDL_Instance, NULL);
+ }
由于1.3版本的改变,只需要设置hwnd,不再象1.26那样还要处理消息循环相关的,具体可跟踪代码,在这后面有个函数:SetupWindowData里面的实现
QT中调用方法:
char windowid[32];
memset(windowid, 0, 32);
sprintf(windowid, "SDL_WINDOWID=0x%lx", state->window_ids[i]); //window_ids[i]是QT中窗口的Wid
SDL_putenv(windowid);
//sprintf(windowid, "SDL_WINDOW_PARENTID=0x%lx", state->window_ids[i+1]);
//SDL_putenv(windowid);
在window下,开发者最好对win32及directshow比较了解,否则对后面的sdl_window,sdl_texture,sdl_overlay,render等会比较困惑. 至于双窗口之间如何通信等,个人没有去应用,感觉它不如QT实现便捷。