Step 1: Create the Windows Framework

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

[This API is not supported and may be altered or unavailable in the future.]

Start by creating the basic framework of a Windows application, including WinMain and a window procedure. The WinMain function is not shown here; call CoInitialize before the message loop to initialize the COM library, and CoUninitialize after the message loop exits. Start with the following minimal window procedure:

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    static BITMAPINFOHEADER *pbmi = NULL;
    static BYTE *pBuffer = NULL;
    switch (msg)
    {
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        if (pbmi) delete [] pbmi;
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, msg, wparam, lparam);
    }
    return 0;
}

When you retrieve a poster frame from the Media Detector, it returns a buffer that contains a BITMAPINFOHEADER structure followed by the image bits. Therefore, define two static variables in the window procedure: pbmi will hold a pointer to the BITMAPINFOHEADER structure, and pBuffer will hold a pointer to the bitmap. The application will allocate the buffer in pbmi using new, so it must delete the buffer before the window is destroyed. The pBuffer pointer is calculated as an offset from pbmi, so there is no need to delete it.

Next: Step 2: Add a Menu Command to Grab a Poster Frame

Grabbing a Poster Frame