如何将 DirectShow 视频播放器嵌入到 SDL Window

How to Embed DirectShow Video Player to SDL Window

我尝试在 SDL Window 中使用 DirectShow 库播放视频文件,我使用 Microsoft Docs 提供的库,当我尝试单独构建它时工作正常,但是代码from main.cpp 需要在 HWND 中创建一个 window 才能工作,我想在现有的 SDL_Window.

中使用它

代码来自 main.cpp

HWND hwnd = CreateWindowEx(0, CLASS_NAME, L"DirectShow Playback", 
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

我的代码

SDL_SysWMinfo info; 
SDL_VERSION(&info.version);
SDL_GetWindowWMInfo(g_window, &info);
HWND hwnd = GetWindow(info.info.win.window, GWL_WNDPROC);

我已经有 SDL_Window* g_windowSDL_Renderer* g_rendererSDL_Thread* video_tid,但似乎不适用于 HWND hwnd

还有,如果我成功了那我就改ShowWindow(hwnd, nCmdShow);?

这里是完整的代码:

TUserFunc(void, PlayVideo, HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow, bool testvideo)
{
    // Register the window class.
    const wchar_t CLASS_NAME[]  = L"Sample Window Class";
    
    WNDCLASS wc = { };
    wc.lpfnWndProc   = WindowProc;
    wc.hInstance     = hInstance;
    wc.lpszClassName = CLASS_NAME;

    RegisterClass(&wc);

       SDL_SysWMinfo info; 
       SDL_VERSION(&info.version);
       SDL_GetWindowWMInfo(g_window, &info);
       HWND hwnd = GetWindow(info.info.win.window, GWL_WNDPROC);

    if (hwnd == NULL)
    {
        NotifyError(NULL, L"CreateWindowEx failed.");
    }

    ShowWindow(hwnd, nCmdShow);

    // Run the message loop.

    MSG msg = { };
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

PD:当我使用 main.cpp 的 HWND hwnd 时,视频播放但处于隐藏状态 window 并且 SDL window 完全冻结

DirectShow 视频渲染器支持所谓的“无窗口模式”,您可以使用它:

Using Windowless Mode

Windowless mode avoids these problems by having the VMR draw directly on the application window's client area, using DirectDraw to clip the video rectangle.

Old Windows SDK 提供相关样本(例如 vmr9/windowless)。

旧的 Windows SDK 是一个名为 Cutscene 的示例,将其与 put_WindowStyle(WS_CHILD) 相结合以实现无边界并将其绑定到 SDL Window 非常完美,谢谢